Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error if config.storeName isn't a String #948

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions dist/localforage.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,12 @@ function isIndexedDBValid() {

var hasFetch = typeof fetch === 'function' && fetch.toString().indexOf('[native code') !== -1;

// Safari <10.1 does not meet our requirements for IDB support (#5572)
// since Safari 10.1 shipped with fetch, we can use that to detect it
// Safari <10.1 does not meet our requirements for IDB support
// (see: https://github.com/pouchdb/pouchdb/issues/5572).
// Safari 10.1 shipped with fetch, we can use that to detect it.
// Note: this creates issues with `window.fetch` polyfills and
// overrides; see:
// https://github.com/localForage/localForage/issues/856
return (!isSafari || hasFetch) && typeof indexedDB !== 'undefined' &&
// some outdated implementations of IDB that appear on Samsung
// and HTC Android devices <4.4 are missing IDBKeyRange
Expand Down Expand Up @@ -2537,8 +2541,10 @@ var LocalForage = function () {
}

for (var i in options) {
if (i === 'storeName') {
if (i === 'storeName' && typeof options[i] === 'string') {
options[i] = options[i].replace(/\W/g, '_');
} else if (i === 'storeName' && typeof options[i] !== 'string') {
return new Error('storeName must be a string');
}

if (i === 'version' && typeof options[i] !== 'number') {
Expand Down
2 changes: 1 addition & 1 deletion dist/localforage.min.js

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions dist/localforage.nopromises.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ function isIndexedDBValid() {

var hasFetch = typeof fetch === 'function' && fetch.toString().indexOf('[native code') !== -1;

// Safari <10.1 does not meet our requirements for IDB support (#5572)
// since Safari 10.1 shipped with fetch, we can use that to detect it
// Safari <10.1 does not meet our requirements for IDB support
// (see: https://github.com/pouchdb/pouchdb/issues/5572).
// Safari 10.1 shipped with fetch, we can use that to detect it.
// Note: this creates issues with `window.fetch` polyfills and
// overrides; see:
// https://github.com/localForage/localForage/issues/856
return (!isSafari || hasFetch) && typeof indexedDB !== 'undefined' &&
// some outdated implementations of IDB that appear on Samsung
// and HTC Android devices <4.4 are missing IDBKeyRange
Expand Down Expand Up @@ -2201,8 +2205,10 @@ var LocalForage = function () {
}

for (var i in options) {
if (i === 'storeName') {
if (i === 'storeName' && typeof options[i] === 'string') {
options[i] = options[i].replace(/\W/g, '_');
} else if (i === 'storeName' && typeof options[i] !== 'string') {
return new Error('storeName must be a string');
}

if (i === 'version' && typeof options[i] !== 'number') {
Expand Down
2 changes: 1 addition & 1 deletion dist/localforage.nopromises.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"test": "node -e \"require('grunt').cli()\" null test"
},
"devDependencies": {
"jslint": "^0.12.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the code using jslint? I mentioned tooling like this belongs in devDependencies if used, but I don't see it being used anywhere in this PR so I think it's best to remove this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I think now it good to go.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it now ready to merge??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be patient; this is an open-source project and we don't always have the time to respond to PRs right away. I do check my issue queues/notifications but I can't get to things right away 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. No worry.

"babel-core": "^6.5.1",
"babel-eslint": "^7.2.3",
"babel-loader": "^6.2.2",
Expand Down
7 changes: 6 additions & 1 deletion src/localforage.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ class LocalForage {
}

for (let i in options) {
if (i === 'storeName') {
if (i === 'storeName' && typeof options[i] === 'string') {
options[i] = options[i].replace(/\W/g, '_');
} else if (
i === 'storeName' &&
typeof options[i] !== 'string'
) {
return new Error('storeName must be a string');
}

if (i === 'version' && typeof options[i] !== 'number') {
Expand Down
11 changes: 11 additions & 0 deletions test/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,15 @@ describe('Config API', function() {
expect(configResult.toString()).to.be(error);
done();
});

it('should throw error on config.storeName not string', function() {
let configResult = localforage.config({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let configResult = localforage.config({
const configResult = localforage.config({

description: 'The offline datastore for my cool app',
driver: localforage.driver(),
name: 'My Cool App',
storeName: 123,
version: 2.0
});
expect(configResult).to.be(new Error('storeName must be a string'));
});
});