Skip to content

Commit

Permalink
Merge pull request #983 from Choices-js/patch-1
Browse files Browse the repository at this point in the history
Fix Sanitization of > Characters
  • Loading branch information
mtriff authored Dec 22, 2021
2 parents f0ec43f + 22f9be0 commit b92823b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/scripts/components/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ describe('components/input', () => {
const value = '<script>somethingMalicious();</script>';
instance.element.value = value;
expect(instance.value).to.equal(
'&lt;script&rt;somethingMalicious();&lt;/script&rt;',
'&lt;script&gt;somethingMalicious();&lt;/script&gt;',
);
});
});
Expand Down
13 changes: 7 additions & 6 deletions src/scripts/lib/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/* eslint-disable no-new-wrappers */
import { expect } from 'chai';
import { stub } from 'sinon';

import {
getRandomNumber,
cloneObject,
diff,
dispatchEvent,
existsInArray,
generateChars,
generateId,
getRandomNumber,
getType,
isType,
sanitise,
sortByAlpha,
sortByScore,
existsInArray,
cloneObject,
dispatchEvent,
diff,
} from './utils';

describe('utils', () => {
Expand Down Expand Up @@ -113,7 +114,7 @@ describe('utils', () => {
const value = '<script>somethingMalicious();</script>';
const output = sanitise(value);
expect(output).to.equal(
'&lt;script&rt;somethingMalicious();&lt;/script&rt;',
'&lt;script&gt;somethingMalicious();&lt;/script&gt;',
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const sanitise = <T>(value: T | string): T | string => {

return value
.replace(/&/g, '&amp;')
.replace(/>/g, '&rt;')
.replace(/>/g, '&gt;')
.replace(/</g, '&lt;')
.replace(/"/g, '&quot;');
};
Expand Down

0 comments on commit b92823b

Please sign in to comment.