Skip to content

Commit

Permalink
Corrideat/task/#2479 string comparison issue (#2504)
Browse files Browse the repository at this point in the history
* normalise string when used in comparison

* Changes to normalize string

---------

Co-authored-by: SebinSong <[email protected]>
  • Loading branch information
corrideat and SebinSong authored Jan 13, 2025
1 parent 0d99f04 commit 0486f23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions frontend/model/contracts/shared/giLodash.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ 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 intial and final punctuation marks,
// which typically are used in smart quote substitution, with a standad
// character
// (reference issue: https://github.com/okTurtles/group-income/issues/2479)
.replace(/[\p{Pf}\p{Pi}]/gu, "'")
// [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 0486f23

Please sign in to comment.