Skip to content

Commit

Permalink
fix(urls): replace base URL regex with url-parse
Browse files Browse the repository at this point in the history
Reimplements #160.

Closes #150.
Closes #160.
  • Loading branch information
tlvince authored and ptitjes committed Nov 17, 2017
1 parent d600426 commit 7472135
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"pouchdb-extend": "0.1.2",
"pouchdb-promise": "6.3.4",
"pouchdb-utils": "6.3.4",
"url-join": "2.0.2"
"url-join": "2.0.2",
"url-parse": "1.2.0"
},
"devDependencies": {
"babel-preset-env": "^1.6.1",
Expand Down
5 changes: 3 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

import urlJoin from 'url-join';
import urlParse from 'url-parse';

function getBaseUrl(db) {
if (typeof db.getUrl === 'function') { // pouchdb pre-6.0.0
return db.getUrl().replace(/[^/]+\/?$/, '');
return urlParse(db.getUrl()).origin;
} else if (db.__opts && db.__opts.prefix) { // PouchDB.defaults
return db.__opts.prefix;
} else { // pouchdb post-6.0.0
return db.name.replace(/[^/]+\/?$/, '');
return urlParse(db.name).origin;
}
}

Expand Down

0 comments on commit 7472135

Please sign in to comment.