Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrideat/task/#2479 string comparison issue #2504

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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