From 9544d22392fadb54d1ff7eb0a3e2ee5f115a18c8 Mon Sep 17 00:00:00 2001 From: SebinSong Date: Tue, 31 Dec 2024 16:46:04 +0900 Subject: [PATCH] normalise string when used in comparison --- frontend/model/contracts/shared/giLodash.js | 9 +++++++++ .../views/containers/group-settings/GroupLeaveModal.vue | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/model/contracts/shared/giLodash.js b/frontend/model/contracts/shared/giLodash.js index d54a1f0fa3..b047600e78 100644 --- a/frontend/model/contracts/shared/giLodash.js +++ b/frontend/model/contracts/shared/giLodash.js @@ -78,6 +78,15 @@ export function randomHexString (length: number): string { return Array.from(randomBytes(length), byte => (byte % 16).toString(16)).join('') } +export function normalizeString (str: string): string { + return str + // [1]. Normalize strings by replacing both apostrophes and single quotes with a standard character (reference issue: https://github.com/okTurtles/group-income/issues/2479) + .replace(/['’]/g, "'") + // [2]. Normalize the string based on 'Canonical equivalence'. eg) 'Amélie' !== 'Amélie' even when they are visually identical because their unicode sequences are different. + // (reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize#canonical_equivalence_normalization) + .normalize('NFC') +} + export function randomIntFromRange (min: number, max: number): number { return Math.floor(Math.random() * (max - min + 1) + min) } diff --git a/frontend/views/containers/group-settings/GroupLeaveModal.vue b/frontend/views/containers/group-settings/GroupLeaveModal.vue index fae65e3289..163f30ac74 100644 --- a/frontend/views/containers/group-settings/GroupLeaveModal.vue +++ b/frontend/views/containers/group-settings/GroupLeaveModal.vue @@ -63,6 +63,7 @@ import BannerSimple from '@components/banners/BannerSimple.vue' import BannerScoped from '@components/banners/BannerScoped.vue' import ButtonSubmit from '@components/ButtonSubmit.vue' import validationsDebouncedMixins from '@view-utils/validationsDebouncedMixins.js' +import { normalizeString } from '@model/contracts/shared/giLodash.js' export default ({ name: 'GroupLeaveModal', @@ -132,7 +133,7 @@ export default ({ confirmation: { [L('This field is required')]: required, [L('Does not match')]: function (value) { - return value === this.code + return normalizeString(value) === normalizeString(this.code) } } }