Skip to content

Commit

Permalink
Merge pull request #990 from Choices-js/fix-search-sanitisation
Browse files Browse the repository at this point in the history
Remove character sanitisation when searching
  • Loading branch information
mtriff authored Dec 31, 2021
2 parents 1b4d355 + 9605f36 commit 781c729
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/scripts/choices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,38 @@ describe('choices', () => {
});
});

describe('events', () => {
describe('search', () => {
beforeEach(() => {
document.body.innerHTML = `
<select data-choice multiple></select>
`;

instance = new Choices('[data-choice]', {
allowHTML: false,
searchEnabled: true,
});
});

it('details are passed', (done) => {
const query =
'This is a <search> query & a "test" with characters that should not be sanitised.';

instance.input.value = query;
instance.input.focus();
instance.passedElement.element.addEventListener('search', (event) => {
expect(event.detail).to.eql({
value: query,
resultCount: 0,
});
done();
});

instance._onKeyUp({ target: null, keyCode: null });
});
});
});

describe('private methods', () => {
describe('_createGroupsFragment', () => {
let _createChoicesFragmentStub;
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ class Choices implements Choices {
this._isSearching = false;
this._store.dispatch(activateChoices(true));
} else if (canSearch) {
this._handleSearch(this.input.value);
this._handleSearch(this.input.rawValue);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/scripts/components/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default class Input {
this.element.value = value;
}

get rawValue(): string {
return this.element.value;
}

addEventListeners(): void {
this.element.addEventListener('paste', this._onPaste);
this.element.addEventListener('input', this._onInput, {
Expand Down

0 comments on commit 781c729

Please sign in to comment.