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 3 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 @@ -69,6 +69,7 @@
"url": "http://github.com/localForage/localForage/issues"
},
"dependencies": {
"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.

This should be in devDependencies, not dependencies, as you don't need jslint to run the repo.

That said: this shouldn't need to be here at all. If we're using a linter it should be eslint, but we aren't using a linter (or, specifically, jslint) anywhere in the codebase or this PR. Could you remove this line please?

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.

Sorry, I forget that this type of dependency came under dev dependencies.

"lie": "3.1.1"
}
}
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
12 changes: 12 additions & 0 deletions test/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,16 @@ describe('Config API', function() {
expect(configResult.toString()).to.be(error);
done();
});

it('should throw error on config.storeName not string', function(done) {
Copy link
Member

Choose a reason for hiding this comment

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

Just a wording suggestion here to clean up the test:

Suggested change
it('should throw error on config.storeName not string', function(done) {
it('should throw error if config.storeName is not a string', function() {

(You also don't need to use done() here since this isn't an asynchronous test.)

Copy link
Author

Choose a reason for hiding this comment

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

Ok. Got it

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'));
done();
tofumatt marked this conversation as resolved.
Show resolved Hide resolved
});
});