diff --git a/src/lib/adapters/Caching.ts b/src/lib/adapters/Caching.ts index 0b43e16045..cba376ba82 100644 --- a/src/lib/adapters/Caching.ts +++ b/src/lib/adapters/Caching.ts @@ -4,7 +4,6 @@ import Logger from '../Logger' import Adapter from '../interfaces/Adapter' import difference from 'lodash/difference' -import url from 'url' import Ordering from '../interfaces/Ordering' import { MissingItemOrderError, @@ -30,7 +29,7 @@ export default class CachingAdapter implements Adapter, BulkImportResource { getLabel():string { const data = this.getData() - return data.username + '@' + url.parse(data.url).hostname + return data.username + '@' + new URL(data.url).hostname } async getBookmarksTree(): Promise { @@ -41,9 +40,13 @@ export default class CachingAdapter implements Adapter, BulkImportResource { if (bm.url === 'data:') { return false } - return Boolean(['https:', 'http:', 'ftp:', 'data:', 'javascript:', 'chrome:', 'file:'].includes( - url.parse(bm.url).protocol - )) + try { + return Boolean(['https:', 'http:', 'ftp:', 'data:', 'javascript:', 'chrome:', 'file:'].includes( + new URL(bm.url).protocol + )) + } catch (e) { + return false + } } async createBookmark(bm:Bookmark):Promise { diff --git a/src/lib/adapters/NextcloudBookmarks.ts b/src/lib/adapters/NextcloudBookmarks.ts index 8232629d0b..daa88440ac 100644 --- a/src/lib/adapters/NextcloudBookmarks.ts +++ b/src/lib/adapters/NextcloudBookmarks.ts @@ -8,7 +8,6 @@ import { Bookmark, Folder, ItemLocation, TItem } from '../Tree' import { Base64 } from 'js-base64' import AsyncLock from 'async-lock' import * as Parallel from 'async-parallel' -import url from 'url' import PQueue from 'p-queue' import flatten from 'lodash/flatten' import { BulkImportResource, LoadFolderChildrenResource, OrderFolderResource } from '../interfaces/Resource' @@ -106,27 +105,26 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes getLabel():string { const data = this.getData() - return data.username.includes('@') ? data.username + ' on ' + url.parse(data.url).hostname : data.username + '@' + url.parse(data.url).hostname + return data.username.includes('@') ? data.username + ' on ' + new URL(data.url).hostname : data.username + '@' + new URL(data.url).hostname } acceptsBookmark(bm: Bookmark):boolean { - return Boolean(~['https:', 'http:', 'ftp:'].indexOf(url.parse(bm.url).protocol)) + try { + return Boolean(~['https:', 'http:', 'ftp:'].indexOf(new URL(bm.url).protocol)) + } catch (e) { + return false + } } normalizeServerURL(input:string):string { - const serverURL = url.parse(input) + const serverURL = new URL(input) const indexLoc = serverURL.pathname.indexOf('index.php') - return url.format({ - protocol: serverURL.protocol, - auth: serverURL.auth, - host: serverURL.host, - port: serverURL.port, - pathname: - serverURL.pathname.substr(0, ~indexLoc ? indexLoc : undefined) + - (!~indexLoc && serverURL.pathname[serverURL.pathname.length - 1] !== '/' - ? '/' - : ''), - }) + if (!serverURL.pathname) serverURL.pathname = '' + serverURL.search = '' + serverURL.hash = '' + serverURL.pathname = serverURL.pathname.substring(0, ~indexLoc ? indexLoc : undefined) + const output = serverURL.toString() + return output + (output[output.length - 1] !== '/' ? '/' : '') } timeout(ms) { diff --git a/src/lib/adapters/WebDav.ts b/src/lib/adapters/WebDav.ts index 02194b2cff..6e6c80aa7e 100644 --- a/src/lib/adapters/WebDav.ts +++ b/src/lib/adapters/WebDav.ts @@ -3,7 +3,6 @@ import XbelSerializer from '../serializers/Xbel' import Logger from '../Logger' import { Base64 } from 'js-base64' -import url from 'url' import Crypto from '../Crypto' import { AuthenticationError, @@ -51,17 +50,12 @@ export default class WebDavAdapter extends CachingAdapter { } normalizeServerURL(input) { - const serverURL = url.parse(input) + const serverURL = new URL(input) if (!serverURL.pathname) serverURL.pathname = '' - return url.format({ - protocol: serverURL.protocol, - auth: serverURL.auth, - host: serverURL.host, - port: serverURL.port, - pathname: - serverURL.pathname + - (serverURL.pathname[serverURL.pathname.length - 1] !== '/' ? '/' : '') - }) + serverURL.search = '' + serverURL.hash = '' + const output = serverURL.toString() + return output + (output[output.length - 1] !== '/' ? '/' : '') } cancel() { diff --git a/src/lib/browser/BrowserTree.ts b/src/lib/browser/BrowserTree.ts index 6bff484e40..b5a735732f 100644 --- a/src/lib/browser/BrowserTree.ts +++ b/src/lib/browser/BrowserTree.ts @@ -6,7 +6,6 @@ import PQueue from 'p-queue' import Account from '../Account' import { Bookmark, Folder, ItemLocation, ItemType } from '../Tree' import Ordering from '../interfaces/Ordering' -import url from 'url' import random from 'random' import seedrandom from 'seedrandom' import { isVivaldi } from './BrowserDetection' @@ -123,7 +122,7 @@ export default class BrowserTree implements IResource { return } try { - if (self.location.protocol === 'moz-extension:' && url.parse(bookmark.url).hostname === 'separator.floccus.org') { + if (self.location.protocol === 'moz-extension:' && new URL(bookmark.url).hostname === 'separator.floccus.org') { const node = await this.queue.add(async() => { Logger.log('(local)CREATE: executing create ', bookmark) return browser.bookmarks.create({ @@ -154,7 +153,7 @@ export default class BrowserTree implements IResource { return } try { - if (self.location.protocol === 'moz-extension:' && url.parse(bookmark.url).hostname === 'separator.floccus.org') { + if (self.location.protocol === 'moz-extension:' && new URL(bookmark.url).hostname === 'separator.floccus.org') { // noop } else { await this.queue.add(async() => {