]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fix: ensure Internet Explorer bookmark dumps can be imported
authorVirtualTam <virtualtam@flibidi.net>
Fri, 12 Aug 2016 21:22:15 +0000 (23:22 +0200)
committerArthurHoaro <arthur@hoa.ro>
Sat, 5 Nov 2016 13:29:52 +0000 (14:29 +0100)
Relates to https://github.com/shaarli/Shaarli/issues/607

Modifications:
- [application][tests] NetscapeBookmarkUtils: more permissive doctype detection

The IE bookmark exports contain extra escape sequences, which can be observed
by binary comparison of the reference input data used in tests:

   $ cmp -b -l -n 8 netscape_basic.htm internet_explorer_encoding.htm

   1  74 <    357 M-o
   2  41 !    273 M-;
   3 104 D    277 M-?
   4 117 O     74 <
   5 103 C     41 !
   6 124 T    104 D
   7 131 Y    117 O
   8 120 P    103 C

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
application/NetscapeBookmarkUtils.php
tests/NetscapeBookmarkUtils/BookmarkImportTest.php
tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm [new file with mode: 0644]

index b99a432e80b3b257aed7b0720e7c6fc44928b5f5..c318125466e73ca932b18e07eacfbe083e5e41f6 100644 (file)
@@ -98,8 +98,7 @@ class NetscapeBookmarkUtils
         $filesize = $files['filetoupload']['size'];
         $data = file_get_contents($files['filetoupload']['tmp_name']);
 
-        // Sniff file type
-        if (! startsWith($data, '<!DOCTYPE NETSCAPE-Bookmark-file-1>')) {
+        if (strpos($data, '<!DOCTYPE NETSCAPE-Bookmark-file-1>') === false) {
             return self::importStatus($filename, $filesize);
         }
 
index 2d4e755758459be305ac26ef9cb480b141058fd7..f0ad500f09a1879803d11b23bb4ed4a9a6924745 100644 (file)
@@ -82,6 +82,34 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(0, count($this->linkDb));
     }
 
+    /**
+     * Ensure IE dumps are supported
+     */
+    public function testImportInternetExplorerEncoding()
+    {
+        $files = file2array('internet_explorer_encoding.htm');
+        $this->assertEquals(
+            'File internet_explorer_encoding.htm (356 bytes) was successfully processed:'
+            .' 1 links imported, 0 links overwritten, 0 links skipped.',
+            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
+        );
+        $this->assertEquals(1, count($this->linkDb));
+        $this->assertEquals(0, count_private($this->linkDb));
+
+        $this->assertEquals(
+            array(
+                'linkdate' => '20160618_173944',
+                'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky',
+                'url' => 'http://hginit.com/',
+                'description' => '',
+                'private' => 0,
+                'tags' => ''
+            ),
+            $this->linkDb->getLinkFromUrl('http://hginit.com/')
+        );
+    }
+
+
     /**
      * Import bookmarks nested in a folder hierarchy
      */
diff --git a/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm b/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm
new file mode 100644 (file)
index 0000000..18703cf
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE NETSCAPE-Bookmark-file-1>
+<!-- This is an automatically generated file.
+It will be read and overwritten.
+Do Not Edit! -->
+<TITLE>Bookmarks</TITLE>
+<H1>Bookmarks</H1>
+<DL><p>
+    <DT><A HREF="http://hginit.com/" ADD_DATE="1466271584" LAST_VISIT="1466271584" LAST_MODIFIED="1466271584" >Hg Init a Mercurial tutorial by Joel Spolsky</A>
+</DL><p>