From cb7940e2deacba66f2510816732be654b255cc70 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 14 Aug 2018 12:26:51 +0200 Subject: Fix hashtags with markdown escape enabled They're now transformed to markdown syntax links before processing them through Parsedown. Fixes #1210 --- tests/plugins/PluginMarkdownTest.php | 14 +++++++++++++- tests/plugins/resources/hashtags.md | 10 ++++++++++ tests/plugins/resources/hashtags.raw | 10 ++++++++++ tests/plugins/resources/markdown.html | 8 ++++---- tests/plugins/resources/markdown.md | 2 +- 5 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tests/plugins/resources/hashtags.md create mode 100644 tests/plugins/resources/hashtags.raw (limited to 'tests/plugins') diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index b31e817f..319a94ba 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -106,6 +106,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $this->assertEquals($text, $reversedText); } + /** + * Test reverse_text2clickable(). + */ + public function testReverseText2clickableHashtags() + { + $text = file_get_contents('tests/plugins/resources/hashtags.raw'); + $md = file_get_contents('tests/plugins/resources/hashtags.md'); + $clickableText = hashtag_autolink($text); + $reversedText = reverse_text2clickable($clickableText); + $this->assertEquals($md, $reversedText); + } + /** * Test reverse_nl2br(). */ @@ -246,7 +258,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $this->conf->get('security.markdown_escape', true), $this->conf->get('security.allowed_protocols') ); - $this->assertEquals($html, $data); + $this->assertEquals($html, $data . PHP_EOL); } /** diff --git a/tests/plugins/resources/hashtags.md b/tests/plugins/resources/hashtags.md new file mode 100644 index 00000000..46326de3 --- /dev/null +++ b/tests/plugins/resources/hashtags.md @@ -0,0 +1,10 @@ +[#lol](?addtag=lol) + + #test + +`#test2` + +``` +bla #bli blo +#bla +``` diff --git a/tests/plugins/resources/hashtags.raw b/tests/plugins/resources/hashtags.raw new file mode 100644 index 00000000..9d2dc98a --- /dev/null +++ b/tests/plugins/resources/hashtags.raw @@ -0,0 +1,10 @@ +#lol + + #test + +`#test2` + +``` +bla #bli blo +#bla +``` diff --git a/tests/plugins/resources/markdown.html b/tests/plugins/resources/markdown.html index f1df4e7e..c3460bf7 100644 --- a/tests/plugins/resources/markdown.html +++ b/tests/plugins/resources/markdown.html @@ -12,11 +12,11 @@
  • two
  • three
  • four
  • -
  • foo <a href="?addtag=foobar" title="Hashtag foobar">#foobar</a>
  • +
  • foo #foobar
  • -

    <a href="?addtag=foobar" title="Hashtag foobar">#foobar</a> foo lol #foo <a href="?addtag=bar" title="Hashtag bar">#bar</a>

    -

    fsdfs http://link.tld <a href="?addtag=foobar" title="Hashtag foobar">#foobar</a> http://link.tld

    +

    #foobar foo lol #foo #bar

    +

    fsdfs http://link.tld #foobar http://link.tld

    http://link.tld #foobar
     next #foo

    Block:

    @@ -30,4 +30,4 @@ next #foo link
    link
    link
    -link

    \ No newline at end of file +link

    diff --git a/tests/plugins/resources/markdown.md b/tests/plugins/resources/markdown.md index b8ebd934..9350a8c7 100644 --- a/tests/plugins/resources/markdown.md +++ b/tests/plugins/resources/markdown.md @@ -31,4 +31,4 @@ lorem ipsum #foobar http://link.tld [link](ftp://test.tld/path/?query=value#hash) [link](magnet:test.tld/path/?query=value#hash) [link](javascript:alert('xss')) -[link](other://test.tld/path/?query=value#hash) \ No newline at end of file +[link](other://test.tld/path/?query=value#hash) -- cgit v1.2.3