diff options
author | ArthurHoaro <arthur@hoa.ro> | 2018-08-14 12:26:51 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2018-08-14 12:26:51 +0200 |
commit | cb7940e2deacba66f2510816732be654b255cc70 (patch) | |
tree | 0f0e99a25f99e88204c5962b4bdd2f15a2b5041c /tests/plugins | |
parent | f28b73b21f705102f8536cd16ea28122aa870e49 (diff) | |
download | Shaarli-cb7940e2deacba66f2510816732be654b255cc70.tar.gz Shaarli-cb7940e2deacba66f2510816732be654b255cc70.tar.zst Shaarli-cb7940e2deacba66f2510816732be654b255cc70.zip |
Fix hashtags with markdown escape enabled
They're now transformed to markdown syntax links before processing them through Parsedown.
Fixes #1210
Diffstat (limited to 'tests/plugins')
-rw-r--r-- | tests/plugins/PluginMarkdownTest.php | 14 | ||||
-rw-r--r-- | tests/plugins/resources/hashtags.md | 10 | ||||
-rw-r--r-- | tests/plugins/resources/hashtags.raw | 10 | ||||
-rw-r--r-- | tests/plugins/resources/markdown.html | 8 | ||||
-rw-r--r-- | tests/plugins/resources/markdown.md | 2 |
5 files changed, 38 insertions, 6 deletions
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 | |||
@@ -107,6 +107,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
107 | } | 107 | } |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * Test reverse_text2clickable(). | ||
111 | */ | ||
112 | public function testReverseText2clickableHashtags() | ||
113 | { | ||
114 | $text = file_get_contents('tests/plugins/resources/hashtags.raw'); | ||
115 | $md = file_get_contents('tests/plugins/resources/hashtags.md'); | ||
116 | $clickableText = hashtag_autolink($text); | ||
117 | $reversedText = reverse_text2clickable($clickableText); | ||
118 | $this->assertEquals($md, $reversedText); | ||
119 | } | ||
120 | |||
121 | /** | ||
110 | * Test reverse_nl2br(). | 122 | * Test reverse_nl2br(). |
111 | */ | 123 | */ |
112 | public function testReverseNl2br() | 124 | public function testReverseNl2br() |
@@ -246,7 +258,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
246 | $this->conf->get('security.markdown_escape', true), | 258 | $this->conf->get('security.markdown_escape', true), |
247 | $this->conf->get('security.allowed_protocols') | 259 | $this->conf->get('security.allowed_protocols') |
248 | ); | 260 | ); |
249 | $this->assertEquals($html, $data); | 261 | $this->assertEquals($html, $data . PHP_EOL); |
250 | } | 262 | } |
251 | 263 | ||
252 | /** | 264 | /** |
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 @@ | |||
1 | [#lol](?addtag=lol) | ||
2 | |||
3 | #test | ||
4 | |||
5 | `#test2` | ||
6 | |||
7 | ``` | ||
8 | bla #bli blo | ||
9 | #bla | ||
10 | ``` | ||
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 @@ | |||
1 | #lol | ||
2 | |||
3 | #test | ||
4 | |||
5 | `#test2` | ||
6 | |||
7 | ``` | ||
8 | bla #bli blo | ||
9 | #bla | ||
10 | ``` | ||
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 @@ | |||
12 | <li><a href="http://link.tld">two</a></li> | 12 | <li><a href="http://link.tld">two</a></li> |
13 | <li><a href="http://link.tld">three</a></li> | 13 | <li><a href="http://link.tld">three</a></li> |
14 | <li><a href="http://link.tld">four</a></li> | 14 | <li><a href="http://link.tld">four</a></li> |
15 | <li>foo <a href="?addtag=foobar" title="Hashtag foobar">#foobar</a></li> | 15 | <li>foo <a href="?addtag=foobar">#foobar</a></li> |
16 | </ol></li> | 16 | </ol></li> |
17 | </ol> | 17 | </ol> |
18 | <p><a href="?addtag=foobar" title="Hashtag foobar">#foobar</a> foo <code>lol #foo</code> <a href="?addtag=bar" title="Hashtag bar">#bar</a></p> | 18 | <p><a href="?addtag=foobar">#foobar</a> foo <code>lol #foo</code> <a href="?addtag=bar">#bar</a></p> |
19 | <p>fsdfs <a href="http://link.tld">http://link.tld</a> <a href="?addtag=foobar" title="Hashtag foobar">#foobar</a> <code>http://link.tld</code></p> | 19 | <p>fsdfs <a href="http://link.tld">http://link.tld</a> <a href="?addtag=foobar">#foobar</a> <code>http://link.tld</code></p> |
20 | <pre><code>http://link.tld #foobar | 20 | <pre><code>http://link.tld #foobar |
21 | next #foo</code></pre> | 21 | next #foo</code></pre> |
22 | <p>Block:</p> | 22 | <p>Block:</p> |
@@ -30,4 +30,4 @@ next #foo</code></pre> | |||
30 | <a href="ftp://test.tld/path/?query=value#hash">link</a><br /> | 30 | <a href="ftp://test.tld/path/?query=value#hash">link</a><br /> |
31 | <a href="magnet:test.tld/path/?query=value#hash">link</a><br /> | 31 | <a href="magnet:test.tld/path/?query=value#hash">link</a><br /> |
32 | <a href="http://alert('xss')">link</a><br /> | 32 | <a href="http://alert('xss')">link</a><br /> |
33 | <a href="http://test.tld/path/?query=value#hash">link</a></p></div> \ No newline at end of file | 33 | <a href="http://test.tld/path/?query=value#hash">link</a></p></div> |
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 | |||
31 | [link](ftp://test.tld/path/?query=value#hash) | 31 | [link](ftp://test.tld/path/?query=value#hash) |
32 | [link](magnet:test.tld/path/?query=value#hash) | 32 | [link](magnet:test.tld/path/?query=value#hash) |
33 | [link](javascript:alert('xss')) | 33 | [link](javascript:alert('xss')) |
34 | [link](other://test.tld/path/?query=value#hash) \ No newline at end of file | 34 | [link](other://test.tld/path/?query=value#hash) |