]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Ignore the case while checking DOCTYPE during the file import 1092/head
authorArthurHoaro <arthur@hoa.ro>
Fri, 23 Feb 2018 19:34:06 +0000 (20:34 +0100)
committerArthurHoaro <arthur@hoa.ro>
Fri, 23 Feb 2018 19:34:06 +0000 (20:34 +0100)
Fixes #1091

application/NetscapeBookmarkUtils.php
tests/NetscapeBookmarkUtils/BookmarkImportTest.php
tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm [new file with mode: 0644]

index dd7057f80e5bd25e1d5fce7bb984644b7c9e2689..2aa2da3b379958b2378e57d24467cf0cac50db5a 100644 (file)
@@ -108,7 +108,7 @@ class NetscapeBookmarkUtils
         $filesize = $files['filetoupload']['size'];
         $data = file_get_contents($files['filetoupload']['tmp_name']);
 
-        if (strpos($data, '<!DOCTYPE NETSCAPE-Bookmark-file-1>') === false) {
+        if (preg_match('/<!DOCTYPE NETSCAPE-Bookmark-file-1>/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'],
index 4961aa2c4f73166d069144776cb574db9a537f67..f0a958cb2e71fed3cd747ef10f906b38b82efc1b 100644 (file)
@@ -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 (file)
index 0000000..8911ad1
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE netscape-bookmark-file-1>
+<TITLE>Bookmarks</TITLE>
+<H1>Bookmarks</H1>
+<DL><p>
+<DT><A HREF="https://private.tld" ADD_DATE="10/Oct/2000:13:55:36 +0300" PRIVATE="1" TAGS="private secret">Secret stuff</A>
+<DD>Super-secret stuff you're not supposed to know about
+<DT><A HREF="http://public.tld" ADD_DATE="1456433748" PRIVATE="0" TAGS="public hello world">Public stuff</A>
+</DL><p>