Skip to content

Commit

Permalink
Merge pull request #318 from thephpleague/bugfix
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
colinodell authored Mar 26, 2018
2 parents 2353513 + f8d0d70 commit ea1f655
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## [Unreleased][unreleased]

## [0.17.2] - 2017-03-25

### Added

- Added new `RegexHelper::isEscapable()` method

### Fixed

- Fixed spec compliance bug where escaped spaces should not be allowed in link destinations

## [0.17.1] - 2017-03-18

### Added
Expand Down Expand Up @@ -615,7 +625,8 @@ An unused constant and static method were deprecated and will be removed in a fu
### Added
- Initial commit (compatible with jgm/stmd:spec.txt @ 0275f34)

[unreleased]: https://github.com/thephpleague/commonmark/compare/0.17.1...HEAD
[unreleased]: https://github.com/thephpleague/commonmark/compare/0.17.2...HEAD
[0.17.2]: https://github.com/thephpleague/commonmark/compare/0.17.1...0.17.2
[0.17.1]: https://github.com/thephpleague/commonmark/compare/0.17.0...0.17.1
[0.17.0]: https://github.com/thephpleague/commonmark/compare/0.16.0...0.17.0
[0.16.0]: https://github.com/thephpleague/commonmark/compare/0.15.7...0.16.0
Expand Down
4 changes: 1 addition & 3 deletions src/Inline/Parser/EscapableParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public function parse(InlineParserContext $inlineContext)
$inlineContext->getContainer()->appendChild(new Newline(Newline::HARDBREAK));

return true;
} elseif ($nextChar !== null &&
preg_match('/' . RegexHelper::PARTIAL_ESCAPABLE . '/', $nextChar)
) {
} elseif (RegexHelper::isEscapable($nextChar)) {
$cursor->advanceBy(2);
$inlineContext->getContainer()->appendChild(new Text($nextChar));

Expand Down
2 changes: 1 addition & 1 deletion src/Util/LinkParserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function parseLinkDestination(Cursor $cursor)
$oldState = $cursor->saveState();
$openParens = 0;
while (($c = $cursor->getCharacter()) !== null) {
if ($c === '\\') {
if ($c === '\\' && RegexHelper::isEscapable($cursor->peek())) {
$cursor->advanceBy(2);
} elseif ($c === '(') {
$cursor->advance();
Expand Down
14 changes: 14 additions & 0 deletions src/Util/RegexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ public static function getInstance()
return self::$instance;
}

/**
* @param string|null $character
*
* @return bool
*/
public static function isEscapable($character)
{
if ($character === null) {
return false;
}

return preg_match('/' . self::PARTIAL_ESCAPABLE . '/', $character) === 1;
}

/**
* Returns a partial regex
*
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/Util/RegexHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ public function testUnescape()
$this->assertEquals('foo(and(bar))', RegexHelper::unescape('foo(and\\(bar\\))'));
}

public function testIsEscapable()
{
$this->assertFalse(RegexHelper::isEscapable(null));
$this->assertFalse(RegexHelper::isEscapable('A'));
$this->assertTrue(RegexHelper::isEscapable('\\'));
}

/**
* @param $regex
* @param $string
Expand Down

0 comments on commit ea1f655

Please sign in to comment.