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

Fix "equals" crashing on unknown value types #16

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/match/matchEquals.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ function MatchEquals (storage, testTables, document) {
value = document[field];

if (document[field] !== undefined) {
const subfilters = storage.fields[field][typeof value][value];
const subfilters = storage.fields[field][typeof value];

if (subfilters !== undefined) {
testTables.addMatch(subfilters);
if (subfilters !== undefined && subfilters[value] !== undefined) {
testTables.addMatch(subfilters[value]);
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/keywords/equals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ describe('DSL.keyword.equals', () => {
});
});

// see https://github.com/kuzzleio/koncorde/issues/13
it('should skip the matching if the document tested property is not of the same type than the known values', () => {
return dsl.register('index', 'collection', {equals: {foo: 'bar'}})
.then(() => {
should(dsl.test('index', 'collection', {foo: ['bar']})).be.an.Array().and.empty();
should(dsl.test('index', 'collection', {foo: {bar: true}})).be.an.Array().and.empty();
});
});

it('should match a document with the subscribed nested keyword', () => {
return dsl.register('index', 'collection', {equals: {'foo.bar.baz': 'qux'}})
.then(subscription => {
Expand Down Expand Up @@ -207,7 +216,6 @@ describe('DSL.keyword.equals', () => {
.length(1);
});
});

});

describe('#removal', () => {
Expand Down