Skip to content

Commit

Permalink
normalise string when used in comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
SebinSong committed Dec 31, 2024
1 parent 160bb62 commit 9544d22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions frontend/model/contracts/shared/giLodash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/views/containers/group-settings/GroupLeaveModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 9544d22

Please sign in to comment.