From 3ff1ce47bc9e512ae67b009296c8ac7a6654c9ad Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 23 Feb 2018 20:34:06 +0100 Subject: Ignore the case while checking DOCTYPE during the file import Fixes #1091 --- application/NetscapeBookmarkUtils.php | 4 ++-- tests/NetscapeBookmarkUtils/BookmarkImportTest.php | 15 +++++++++++++++ tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index dd7057f8..2aa2da3b 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php @@ -108,7 +108,7 @@ class NetscapeBookmarkUtils $filesize = $files['filetoupload']['size']; $data = file_get_contents($files['filetoupload']['tmp_name']); - if (strpos($data, '') === false) { + if (preg_match('//i', $data) === 0) { return self::importStatus($filename, $filesize); } @@ -160,7 +160,7 @@ class NetscapeBookmarkUtils } else if ($post['privacy'] == 'public') { // all imported links are public $private = 0; - } + } $newLink = array( 'title' => $bkm['title'], diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php index 4961aa2c..f0a958cb 100644 --- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php +++ b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php @@ -126,6 +126,21 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase $this->assertEquals(0, count($this->linkDb)); } + /** + * Attempt to import bookmarks from a file with a lowercase Doctype + */ + public function testImportLowecaseDoctype() + { + $files = file2array('lowercase_doctype.htm'); + $this->assertStringMatchesFormat( + 'File lowercase_doctype.htm (386 bytes) was successfully processed in %d seconds:' + .' 2 links imported, 0 links overwritten, 0 links skipped.', + NetscapeBookmarkUtils::import(null, $files, $this->linkDb, $this->conf, $this->history) + ); + $this->assertEquals(2, count($this->linkDb)); + } + + /** * Ensure IE dumps are supported */ diff --git a/tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm b/tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm new file mode 100644 index 00000000..8911ad19 --- /dev/null +++ b/tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm @@ -0,0 +1,8 @@ + +Bookmarks +

Bookmarks

+

+

Secret stuff +
Super-secret stuff you're not supposed to know about +
Public stuff +

-- cgit v1.2.3