From 0849fa881a98d8f1231a6959d40e7eda4a8ffc06 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 31 Jan 2017 18:29:56 +0100 Subject: [PATCH] more cleanup in embedSVG now comments and line breaks between tags are removed --- _test/data/media/wiki/test.svg | 11 ++++++++ _test/tests/inc/common_embedSVG.test.php | 34 ++++++++++++++++++++++++ inc/common.php | 6 +++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 _test/data/media/wiki/test.svg create mode 100644 _test/tests/inc/common_embedSVG.test.php diff --git a/_test/data/media/wiki/test.svg b/_test/data/media/wiki/test.svg new file mode 100644 index 0000000000..3c2d541841 --- /dev/null +++ b/_test/data/media/wiki/test.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/_test/tests/inc/common_embedSVG.test.php b/_test/tests/inc/common_embedSVG.test.php new file mode 100644 index 0000000000..1b1b5edbc9 --- /dev/null +++ b/_test/tests/inc/common_embedSVG.test.php @@ -0,0 +1,34 @@ +'; + + ob_start(); + $this->assertTrue(embedSVG($file)); + $svg = ob_get_clean(); + $this->assertEquals($clean, $svg); + } + + /** + * embed should fail because of the file size limit + */ + function test_fail() { + $file = mediaFN('wiki:test.svg'); + ob_start(); + $this->assertFalse(embedSVG($file, 100)); + $svg = ob_get_clean(); + $this->assertEquals('', $svg); + } + +} diff --git a/inc/common.php b/inc/common.php index ad93ba6a26..5620e000c0 100644 --- a/inc/common.php +++ b/inc/common.php @@ -2031,8 +2031,10 @@ function embedSVG($file, $maxsize = 2048) { if(filesize($file) > $maxsize) return false; if(!is_readable($file)) return false; $content = file_get_contents($file); - $content = preg_replace('/<\?xml .*?\?>/i', '', $content); - $content = preg_replace('//i', '', $content); + $content = preg_replace('/)/s','', $content); // comments + $content = preg_replace('/<\?xml .*?\?>/i', '', $content); // xml header + $content = preg_replace('//i', '', $content); // doc type + $content = preg_replace('/>\s+<', $content); // newlines between tags $content = trim($content); if(substr($content, 0, 5) !== '