aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-08-13 13:59:12 +0200
committerGitHub <noreply@github.com>2016-08-13 13:59:12 +0200
commitf396134bf1b6080f9cfc55f46c59cd50f440f556 (patch)
tree66bf1b75a3bfd4f1862cd06e0a4c1d162e365ca9
parenta34d6da642acda37b04e4c5d732d42a84df65068 (diff)
parentf4ad7bde56b769cea0a2a26eb739e57500705555 (diff)
downloadShaarli-f396134bf1b6080f9cfc55f46c59cd50f440f556.tar.gz
Shaarli-f396134bf1b6080f9cfc55f46c59cd50f440f556.tar.zst
Shaarli-f396134bf1b6080f9cfc55f46c59cd50f440f556.zip
Merge pull request #635 from virtualtam/fix/import/ie
Fix: ensure Internet Explorer bookmark dumps can be imported
-rw-r--r--application/NetscapeBookmarkUtils.php3
-rw-r--r--tests/NetscapeBookmarkUtils/BookmarkImportTest.php28
-rw-r--r--tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm9
3 files changed, 38 insertions, 2 deletions
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index b99a432e..c3181254 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -98,8 +98,7 @@ class NetscapeBookmarkUtils
98 $filesize = $files['filetoupload']['size']; 98 $filesize = $files['filetoupload']['size'];
99 $data = file_get_contents($files['filetoupload']['tmp_name']); 99 $data = file_get_contents($files['filetoupload']['tmp_name']);
100 100
101 // Sniff file type 101 if (strpos($data, '<!DOCTYPE NETSCAPE-Bookmark-file-1>') === false) {
102 if (! startsWith($data, '<!DOCTYPE NETSCAPE-Bookmark-file-1>')) {
103 return self::importStatus($filename, $filesize); 102 return self::importStatus($filename, $filesize);
104 } 103 }
105 104
diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
index 2d4e7557..f0ad500f 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
+++ b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
@@ -83,6 +83,34 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
83 } 83 }
84 84
85 /** 85 /**
86 * Ensure IE dumps are supported
87 */
88 public function testImportInternetExplorerEncoding()
89 {
90 $files = file2array('internet_explorer_encoding.htm');
91 $this->assertEquals(
92 'File internet_explorer_encoding.htm (356 bytes) was successfully processed:'
93 .' 1 links imported, 0 links overwritten, 0 links skipped.',
94 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
95 );
96 $this->assertEquals(1, count($this->linkDb));
97 $this->assertEquals(0, count_private($this->linkDb));
98
99 $this->assertEquals(
100 array(
101 'linkdate' => '20160618_173944',
102 'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky',
103 'url' => 'http://hginit.com/',
104 'description' => '',
105 'private' => 0,
106 'tags' => ''
107 ),
108 $this->linkDb->getLinkFromUrl('http://hginit.com/')
109 );
110 }
111
112
113 /**
86 * Import bookmarks nested in a folder hierarchy 114 * Import bookmarks nested in a folder hierarchy
87 */ 115 */
88 public function testImportNested() 116 public function testImportNested()
diff --git a/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm b/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm
new file mode 100644
index 00000000..18703cf6
--- /dev/null
+++ b/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm
@@ -0,0 +1,9 @@
1<!DOCTYPE NETSCAPE-Bookmark-file-1>
2<!-- This is an automatically generated file.
3It will be read and overwritten.
4Do Not Edit! -->
5<TITLE>Bookmarks</TITLE>
6<H1>Bookmarks</H1>
7<DL><p>
8 <DT><A HREF="http://hginit.com/" ADD_DATE="1466271584" LAST_VISIT="1466271584" LAST_MODIFIED="1466271584" >Hg Init a Mercurial tutorial by Joel Spolsky</A>
9</DL><p>