aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-05-29 19:33:20 +0200
committerGitHub <noreply@github.com>2018-05-29 19:33:20 +0200
commitcdebf7f9b408f4034b03644a91461f3454c6c039 (patch)
treec0bb89271fa80c048bb060b8bb8a9310ad55bb90
parent73da3a269bd3a636b4764f858e42dcc096e5e0a5 (diff)
parentdd6794cff8a1f26c4d08544d89e1df1f521dcb26 (diff)
downloadShaarli-cdebf7f9b408f4034b03644a91461f3454c6c039.tar.gz
Shaarli-cdebf7f9b408f4034b03644a91461f3454c6c039.tar.zst
Shaarli-cdebf7f9b408f4034b03644a91461f3454c6c039.zip
Merge pull request #1140 from ArthurHoaro/hotfix/markdown-rss-permalink
Fix feed permalink rendering with markdown escape set to true
-rw-r--r--plugins/markdown/markdown.php8
-rw-r--r--tests/plugins/PluginMarkdownTest.php55
2 files changed, 63 insertions, 0 deletions
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index 2f24e417..821bb125 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -6,6 +6,8 @@
6 * Shaare's descriptions are parsed with Markdown. 6 * Shaare's descriptions are parsed with Markdown.
7 */ 7 */
8 8
9use Shaarli\Config\ConfigManager;
10
9/* 11/*
10 * If this tag is used on a shaare, the description won't be processed by Parsedown. 12 * If this tag is used on a shaare, the description won't be processed by Parsedown.
11 */ 13 */
@@ -50,6 +52,7 @@ function hook_markdown_render_feed($data, $conf)
50 $value = stripNoMarkdownTag($value); 52 $value = stripNoMarkdownTag($value);
51 continue; 53 continue;
52 } 54 }
55 $value['description'] = reverse_feed_permalink($value['description']);
53 $value['description'] = process_markdown( 56 $value['description'] = process_markdown(
54 $value['description'], 57 $value['description'],
55 $conf->get('security.markdown_escape', true), 58 $conf->get('security.markdown_escape', true),
@@ -244,6 +247,11 @@ function reverse_space2nbsp($description)
244 return preg_replace('/(^| )&nbsp;/m', '$1 ', $description); 247 return preg_replace('/(^| )&nbsp;/m', '$1 ', $description);
245} 248}
246 249
250function reverse_feed_permalink($description)
251{
252 return preg_replace('@&#8212; <a href="([^"]+)" title="[^"]+">(\w+)</a>$@im', '&#8212; [$2]($1)', $description);
253}
254
247/** 255/**
248 * Replace not whitelisted protocols with http:// in given description. 256 * Replace not whitelisted protocols with http:// in given description.
249 * 257 *
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php
index ddc2728d..b31e817f 100644
--- a/tests/plugins/PluginMarkdownTest.php
+++ b/tests/plugins/PluginMarkdownTest.php
@@ -50,6 +50,30 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
50 } 50 }
51 51
52 /** 52 /**
53 * Test render_feed hook.
54 */
55 public function testMarkdownFeed()
56 {
57 $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
58 $markdown .= '&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
59 $data = array(
60 'links' => array(
61 0 => array(
62 'description' => $markdown,
63 ),
64 ),
65 );
66
67 $data = hook_markdown_render_feed($data, $this->conf);
68 $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
69 $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
70 $this->assertStringEndsWith(
71 '&#8212; <a href="http://domain.tld/?0oc_VQ">Permalien</a></p></div>',
72 $data['links'][0]['description']
73 );
74 }
75
76 /**
53 * Test render_daily hook. 77 * Test render_daily hook.
54 * Only check that there is basic markdown rendering. 78 * Only check that there is basic markdown rendering.
55 */ 79 */
@@ -104,6 +128,37 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
104 $this->assertEquals($text, $reversedText); 128 $this->assertEquals($text, $reversedText);
105 } 129 }
106 130
131 public function testReverseFeedPermalink()
132 {
133 $text = 'Description... ';
134 $text .= '&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
135 $expected = 'Description... &#8212; [Permalien](http://domain.tld/?0oc_VQ)';
136 $processedText = reverse_feed_permalink($text);
137
138 $this->assertEquals($expected, $processedText);
139 }
140
141 public function testReverseLastFeedPermalink()
142 {
143 $text = 'Description... ';
144 $text .= '<br>&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
145 $expected = $text;
146 $text .= '<br>&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
147 $expected .= '<br>&#8212; [Permalien](http://domain.tld/?0oc_VQ)';
148 $processedText = reverse_feed_permalink($text);
149
150 $this->assertEquals($expected, $processedText);
151 }
152
153 public function testReverseNoFeedPermalink()
154 {
155 $text = 'Hello! Where are you from?';
156 $expected = $text;
157 $processedText = reverse_feed_permalink($text);
158
159 $this->assertEquals($expected, $processedText);
160 }
161
107 /** 162 /**
108 * Test sanitize_html(). 163 * Test sanitize_html().
109 */ 164 */