From 2bfabe5b80f3392a97f0cdb0d05d1751d2786ed1 Mon Sep 17 00:00:00 2001 From: Andrew Kovalyov Date: Tue, 5 May 2015 12:27:05 +0200 Subject: [PATCH 1/4] Add phpunit ~4.5 to require-dev section --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 21cae6c..07e38a3 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,9 @@ "symfony/framework-bundle": "~2.1", "michelf/php-markdown": "1.4.*" }, - + "require-dev": { + "phpunit/phpunit": "~4.5" + }, "suggest": { "symfony/twig-bundle": "to use the Twig markdown filter", "ext-sundown": "to use optional support for php-sundown extension instead of php implementation" From 8423632a15795a0e872dae6850419f09c92e3589 Mon Sep 17 00:00:00 2001 From: Andrew Kovalyov Date: Tue, 5 May 2015 12:27:51 +0200 Subject: [PATCH 2/4] Fixed invalid logic of configuration which lead to double-escaping of html entities --- Parser/MarkdownParser.php | 4 ++-- Tests/FeatureTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Parser/MarkdownParser.php b/Parser/MarkdownParser.php index 2e63266..df55061 100644 --- a/Parser/MarkdownParser.php +++ b/Parser/MarkdownParser.php @@ -101,10 +101,10 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface if (!$this->features['auto_link']) { unset($this->span_gamut['doAutoLinks']); } - if (!$this->features['entities'] && !$this->features['no_html']) { + if (true === $this->features['entities']) { $this->no_entities = true; } - if ($this->features['no_html']) { + if (true === $this->features['no_html']) { $this->no_html = true; } } diff --git a/Tests/FeatureTest.php b/Tests/FeatureTest.php index bf44034..a606d74 100644 --- a/Tests/FeatureTest.php +++ b/Tests/FeatureTest.php @@ -792,4 +792,15 @@ EOF; $this->assertEquals($html, $parser->transform($text)); } + + /** + * @depends testParser + */ + public function testParagraphContainingBoldContainingAmpersandEscapesProperly($parser) { + $text = "Look ma! I can use **beautiful & bold** text with ampersands."; + + $expectedResult = "

Look ma! I can use beautiful & bold text with ampersands.

\n"; + + $this->assertEquals($expectedResult, $parser->transform($text)); + } } From bd9170ee10a0abfbb093c4e0e50495c426fcea5a Mon Sep 17 00:00:00 2001 From: Andrew Kovalyov Date: Tue, 5 May 2015 12:39:37 +0200 Subject: [PATCH 3/4] Fix default configuration --- Parser/MarkdownParser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Parser/MarkdownParser.php b/Parser/MarkdownParser.php index df55061..3050c54 100644 --- a/Parser/MarkdownParser.php +++ b/Parser/MarkdownParser.php @@ -37,7 +37,7 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface 'html_block' => true, 'auto_link' => true, 'auto_mailto' => true, - 'entities' => false, + 'entities' => true, 'no_html' => false, ); @@ -101,7 +101,7 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface if (!$this->features['auto_link']) { unset($this->span_gamut['doAutoLinks']); } - if (true === $this->features['entities']) { + if (false === $this->features['entities']) { $this->no_entities = true; } if (true === $this->features['no_html']) { From 8d4254676ac25d697adada8db294eb7d16ab214b Mon Sep 17 00:00:00 2001 From: Andrew Kovalyov Date: Tue, 5 May 2015 12:39:53 +0200 Subject: [PATCH 4/4] Add test case to cover configuration --- Tests/FeatureTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/FeatureTest.php b/Tests/FeatureTest.php index a606d74..4db829e 100644 --- a/Tests/FeatureTest.php +++ b/Tests/FeatureTest.php @@ -803,4 +803,15 @@ EOF; $this->assertEquals($expectedResult, $parser->transform($text)); } + + /** + * @depends testParser + */ + public function testEscapedLink($parser) { + $link = "http://images.google.com/images?num=30&q=larry+bird"; + + $expectedResult = "

http://images.google.com/images?num=30&q=larry+bird

\n"; + + $this->assertEquals($expectedResult, $parser->transform($link)); + } }