Skip to content

Commit

Permalink
🐛 Fix RegExp bug when normalizing repeated characters in a string
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Jul 13, 2019
1 parent 65ea1eb commit d4eecf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion normalize_diacritics/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,6 @@ export const diacritics: Diacritics[] = [
// tslint:enable:max-line-length

export function removeDiacritics(s: string) {
const normalized = diacritics.find(n => n.diacritics.test(s));
const normalized = diacritics.find(n => (new RegExp(n.diacritics)).test(s));
return null == normalized ? s : normalized.letter;
}
10 changes: 9 additions & 1 deletion normalize_diacritics/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ async function willNormalizeNonAccentedCharacter() {
assertStrictEq(await normalize("\u00d8"), "O");
}

async function willNormalizeRepeatedCharacters() {
assertStrictEq(await normalize("éééé"), "eeee");
assertStrictEq(await normalize("åååå"), "aaaa");
assertStrictEq(await normalize("éåéåéåéå"), "eaeaeaea");
assertStrictEq(await normalize("åéåéåéåé"), "aeaeaeae");
}

prepareTest([
willSkipNormalizationForEmptyCharacter,
willNormalizeSingleCharacter,
willNormalizeAccentedCharacters,
willNormalizeAccentedCharactersWithoutUsingNativeFunction,
willReturnOriginalCharacterWhenNoMatchFound,
willNormalizeNonAccentedCharacter
willNormalizeNonAccentedCharacter,
willNormalizeRepeatedCharacters,
], "normalize_diacritics");

0 comments on commit d4eecf1

Please sign in to comment.