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

Catch more types of search inputs in stripDiacritics #21174

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 11 additions & 2 deletions src/common/string/strip-diacritics.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
export const stripDiacritics = (str) =>
str.normalize("NFD").replace(/[\u0300-\u036F]/g, "");
export function stripDiacritics(
str: string | readonly string[] | undefined
): any {
if (str === undefined) {
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify a more appropriate return type instead of any.

Using any as a return type defeats the purpose of TypeScript's static type checking. Consider specifying a more precise type.

- export function stripDiacritics(
-   str: string | readonly string[] | undefined
- ): any {
+ export function stripDiacritics(
+   str: string | readonly string[] | undefined
+ ): string | string[] | undefined {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function stripDiacritics(
str: string | readonly string[] | undefined
): any {
export function stripDiacritics(
str: string | readonly string[] | undefined
): string | string[] | undefined {
Tools
Biome

[error] 3-3: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.

return str;
}
if (typeof str === "string") {
return str.normalize("NFD").replace(/[\u0300-\u036F]/g, "");
}
return str.map((s) => s.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a safer character class in regular expressions.

The current implementation may lead to issues due to a misleading character class.

- return str.map((s) => s.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
+ return str.map((s) => s.normalize("NFD").replace(/[\u0300-\u036f]/g, ""));

Committable suggestion was skipped due to low confidence.

Tools
Biome

[error] 10-10: Unexpected combined character in the character class. (lint/suspicious/noMisleadingCharacterClass)

Loading