Commit 6f028440 authored by Jiachi Liu's avatar Jiachi Liu

only check on certain chars

parent 61b210f8
...@@ -35,8 +35,9 @@ export function encodeMojibake(input: string): string { ...@@ -35,8 +35,9 @@ export function encodeMojibake(input: string): string {
* @returns The decoded UTF-8 string, or the original if not Mojibake * @returns The decoded UTF-8 string, or the original if not Mojibake
*/ */
export function decodeMojibake(input: string): string { export function decodeMojibake(input: string): string {
// Check if value contains non-ASCII characters that could be Mojibake // Check if value contains Latin-1 extended characters (128-255) that could be Mojibake.
// We use [\x80-\xFF] instead of [^\u0000-\u007F] because Mojibake only produces
// characters in the Latin-1 range (0-255), not full Unicode.
if (!/[\x80-\xFF]/.test(input)) { if (!/[\x80-\xFF]/.test(input)) {
return input return input
} }
......
...@@ -177,6 +177,10 @@ export function normalizeNextQueryParam(key: string): null | string { ...@@ -177,6 +177,10 @@ export function normalizeNextQueryParam(key: string): null | string {
* Checks if a string contains any non-ASCII characters (code points > 127). * Checks if a string contains any non-ASCII characters (code points > 127).
* ASCII characters are in the range U+0000 to U+007F. * ASCII characters are in the range U+0000 to U+007F.
* *
* We use [^\u0000-\u007F] (matches anything outside ASCII) instead of [\x80-\xFF]
* (matches only Latin-1 extended 128-255) because HTTP headers may contain
* any Unicode character that needs encoding, not just Latin-1.
*
* @param value - The string to check * @param value - The string to check
* @returns true if the string contains non-ASCII characters * @returns true if the string contains non-ASCII characters
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment