From 8c4e60186d393a7c42b6bc09e81ba3051092076e Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 30 May 2016 18:51:00 +0200 Subject: The tag is no longer private A private tag is never loaded for visitor, making this feature useless. --- tests/plugins/PluginMarkdownTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/plugins/PluginMarkdownTest.php') diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index fa7e1d52..3593a556 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -125,7 +125,8 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $data = array( 'links' => array(array( 'description' => $str, - 'tags' => NO_MD_TAG + 'tags' => NO_MD_TAG, + 'taglist' => array(NO_MD_TAG), )) ); @@ -140,7 +141,8 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase // nth link 0 => array( 'formatedDescription' => $str, - 'tags' => NO_MD_TAG + 'tags' => NO_MD_TAG, + 'taglist' => array(), ), ), ), -- cgit v1.2.3 From c5941f316a49c94eff354b63e75b3add98ac4aea Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 21 Oct 2016 12:38:38 +0200 Subject: Fix an issue with links not being reversed in code blocks Fixes #672 + Markdown to HTML unit test --- tests/plugins/PluginMarkdownTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/plugins/PluginMarkdownTest.php') diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 3593a556..12bdda24 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -151,4 +151,17 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $data = hook_markdown_render_daily($data); $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); } + + /** + * Test hashtag links processed with markdown. + */ + function testMarkdownHashtagLinks() + { + $md = file_get_contents('tests/plugins/resources/markdown.md'); + $md = format_description($md); + $html = file_get_contents('tests/plugins/resources/markdown.html'); + + $data = process_markdown($md); + $this->assertEquals($html, $data); + } } -- cgit v1.2.3 From 266e3fe5c8961aaf089bad16b9e4c54de1aaff40 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 13 Nov 2016 16:51:21 +0100 Subject: Markdown: fixes feed rendering with nomarkdown tag * make sure we match exactly `nomarkdown` tag * pass the whole link data to stripNoMarkdownTag() to: * strip the noMD tag in taglist (array) * strip the tag in tags (string) Fixes #689 tmp --- tests/plugins/PluginMarkdownTest.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests/plugins/PluginMarkdownTest.php') diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 12bdda24..17ef2280 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -8,8 +8,8 @@ require_once 'application/Utils.php'; require_once 'plugins/markdown/markdown.php'; /** - * Class PlugQrcodeTest - * Unit test for the QR-Code plugin + * Class PluginMarkdownTest + * Unit test for the Markdown plugin */ class PluginMarkdownTest extends PHPUnit_Framework_TestCase { @@ -130,8 +130,11 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase )) ); - $data = hook_markdown_render_linklist($data); - $this->assertEquals($str, $data['links'][0]['description']); + $processed = hook_markdown_render_linklist($data); + $this->assertEquals($str, $processed['links'][0]['description']); + + $processed = hook_markdown_render_feed($data); + $this->assertEquals($str, $processed['links'][0]['description']); $data = array( // Columns data @@ -152,6 +155,24 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); } + /** + * Test that a close value to nomarkdown is not understand as nomarkdown (previous value `.nomarkdown`). + */ + function testNoMarkdownNotExcactlyMatching() + { + $str = 'All _work_ and `no play` makes Jack a *dull* boy.'; + $data = array( + 'links' => array(array( + 'description' => $str, + 'tags' => '.' . NO_MD_TAG, + 'taglist' => array('.'. NO_MD_TAG), + )) + ); + + $data = hook_markdown_render_feed($data); + $this->assertContains('', $data['links'][0]['description']); + } + /** * Test hashtag links processed with markdown. */ -- cgit v1.2.3 From 9ff17ae20effa5d54fd8481c19518123590e3bd0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 27 Feb 2017 19:45:55 +0100 Subject: Add markdown_escape setting This setting allows to escape HTML in markdown rendering or not. The goal behind it is to avoid XSS issue in shared instances. More info: * the setting is set to true by default * it is set to false for anyone who already have the plugin enabled (avoid breaking existing entries) * improve the HTML sanitization when the setting is set to false - but don't consider it XSS proof * mention the setting in the plugin README --- tests/plugins/PluginMarkdownTest.php | 57 ++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'tests/plugins/PluginMarkdownTest.php') diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 17ef2280..f1e1acf8 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -13,12 +13,18 @@ require_once 'plugins/markdown/markdown.php'; */ class PluginMarkdownTest extends PHPUnit_Framework_TestCase { + /** + * @var ConfigManager instance. + */ + protected $conf; + /** * Reset plugin path */ function setUp() { PluginManager::$PLUGINS_PATH = 'plugins'; + $this->conf = new ConfigManager('tests/utils/config/configJson'); } /** @@ -36,7 +42,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase ), ); - $data = hook_markdown_render_linklist($data); + $data = hook_markdown_render_linklist($data, $this->conf); $this->assertNotFalse(strpos($data['links'][0]['description'], '

')); $this->assertNotFalse(strpos($data['links'][0]['description'], '

')); } @@ -61,7 +67,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase ), ); - $data = hook_markdown_render_daily($data); + $data = hook_markdown_render_daily($data, $this->conf); $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '

')); $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '

')); } @@ -110,6 +116,8 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $output = escape($input); $input .= 'link'; $output .= 'link'; + $input .= 'link'; + $output .= 'link'; $this->assertEquals($output, sanitize_html($input)); // Do not touch escaped HTML. $input = escape($input); @@ -130,10 +138,10 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase )) ); - $processed = hook_markdown_render_linklist($data); + $processed = hook_markdown_render_linklist($data, $this->conf); $this->assertEquals($str, $processed['links'][0]['description']); - $processed = hook_markdown_render_feed($data); + $processed = hook_markdown_render_feed($data, $this->conf); $this->assertEquals($str, $processed['links'][0]['description']); $data = array( @@ -151,7 +159,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase ), ); - $data = hook_markdown_render_daily($data); + $data = hook_markdown_render_daily($data, $this->conf); $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); } @@ -169,7 +177,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase )) ); - $data = hook_markdown_render_feed($data); + $data = hook_markdown_render_feed($data, $this->conf); $this->assertContains('', $data['links'][0]['description']); } @@ -185,4 +193,41 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $data = process_markdown($md); $this->assertEquals($html, $data); } + + /** + * Make sure that the HTML tags are escaped. + */ + public function testMarkdownWithHtmlEscape() + { + $md = '**strong** strong'; + $html = '

strong <strong>strong</strong>

'; + $data = array( + 'links' => array( + 0 => array( + 'description' => $md, + ), + ), + ); + $data = hook_markdown_render_linklist($data, $this->conf); + $this->assertEquals($html, $data['links'][0]['description']); + } + + /** + * Make sure that the HTML tags aren't escaped with the setting set to false. + */ + public function testMarkdownWithHtmlNoEscape() + { + $this->conf->set('security.markdown_escape', false); + $md = '**strong** strong'; + $html = '

strong strong

'; + $data = array( + 'links' => array( + 0 => array( + 'description' => $md, + ), + ), + ); + $data = hook_markdown_render_linklist($data, $this->conf); + $this->assertEquals($html, $data['links'][0]['description']); + } } -- cgit v1.2.3