Skip to content

Unable to import bookmarks from Safari #2152

@mattrose

Description

@mattrose

I was trying to import my bookmarks from a safari export and I got the error below.

I traced it down to the fact that, even though Safari says it exports to a bookmarks file that's compatible with netscape, it doesn't actually include the date that the bookmark was added. When the Netscape Bookmark Decoder parses the date, it just sets the 'dateCreated' to an empty string, and then the bookmark importer prepends an @ symbol to the dateCreated string to parse the string as a DateTime obj. In this case, the parser just sets the date to @ , which can't be imported as a DateTime.

$newLinkDate = new DateTime('@' . $bkm['dateCreated']);

I fixed it using the following code

           } else { 
                if ( $bkm['dateCreated'] == "" ) {
                    $newLinkDate = new DateTime();
                } else {
                    $newLinkDate = new DateTime('@' . $bkm['dateCreated']);
                }
                $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
                $link->setCreated($newLinkDate);
            } 

I can open a PR if that's preferred, or someone can just take the code and make a PR themselves.

Failed to parse time string (@) at position 0 (@): Unexpected character
/netvol/local/share/shaarli/application/netscape/NetscapeBookmarkUtils.php159
#0 /netvol/local/share/shaarli/application/netscape/NetscapeBookmarkUtils.php(159): DateTime->__construct()
#1 /netvol/local/share/shaarli/application/front/controller/admin/ImportController.php(76): Shaarli\Netscape\NetscapeBookmarkUtils->import()
#2 [internal function]: Shaarli\Front\Controller\Admin\ImportController->import()
#3 /netvol/local/share/shaarli/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(40): call_user_func()
#4 /netvol/local/share/shaarli/vendor/slim/slim/Slim/Route.php(281): Slim\Handlers\Strategies\RequestResponse->__invoke()
#5 /netvol/local/share/shaarli/application/front/ShaarliMiddleware.php(55): Slim\Route->__invoke()
#6 /netvol/local/share/shaarli/application/front/ShaarliAdminMiddleware.php(25): Shaarli\Front\ShaarliMiddleware->__invoke()
#7 [internal function]: Shaarli\Front\ShaarliAdminMiddleware->__invoke()
#8 /netvol/local/share/shaarli/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()
#9 [internal function]: Slim\DeferredCallable->__invoke()
#10 /netvol/local/share/shaarli/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()
#11 /netvol/local/share/shaarli/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\Route->Slim\{closure}()
#12 /netvol/local/share/shaarli/vendor/slim/slim/Slim/Route.php(268): Slim\Route->callMiddlewareStack()
#13 /netvol/local/share/shaarli/vendor/slim/slim/Slim/App.php(503): Slim\Route->run()
#14 /netvol/local/share/shaarli/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->__invoke()
#15 /netvol/local/share/shaarli/vendor/slim/slim/Slim/App.php(392): Slim\App->callMiddlewareStack()
#16 /netvol/local/share/shaarli/vendor/slim/slim/Slim/App.php(297): Slim\App->process()
#17 /netvol/local/share/shaarli/index.php(202): Slim\App->run()
#18 {main}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugit's broken!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions