From d4eecf1476f28e831c1b9420b4f5cbae06d4e990 Mon Sep 17 00:00:00 2001 From: "Rong Sen Ng (motss)" Date: Sun, 14 Jul 2019 01:42:10 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20RegExp=20bug=20when=20norm?= =?UTF-8?q?alizing=20repeated=20characters=20in=20a=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- normalize_diacritics/helpers.ts | 2 +- normalize_diacritics/normalize.test.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/normalize_diacritics/helpers.ts b/normalize_diacritics/helpers.ts index 223c378..b062639 100644 --- a/normalize_diacritics/helpers.ts +++ b/normalize_diacritics/helpers.ts @@ -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; } diff --git a/normalize_diacritics/normalize.test.ts b/normalize_diacritics/normalize.test.ts index 4d62441..46a7e35 100644 --- a/normalize_diacritics/normalize.test.ts +++ b/normalize_diacritics/normalize.test.ts @@ -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");