Skip to content

Commit 795df68

Browse files
committed
chore: update
1 parent 0460409 commit 795df68

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

app/router.options.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import type { RouterConfig } from 'nuxt/schema'
22

3+
/**
4+
* Restore RFC 3986 unreserved/safe characters that encodeURIComponent encodes
5+
* but are readable and safe in query strings: @ / : ,
6+
*/
7+
function readableEncode(value: string): string {
8+
return encodeURIComponent(value)
9+
.replace(/%40/g, '@')
10+
.replace(/%2F/gi, '/')
11+
.replace(/%3A/gi, ':')
12+
.replace(/%2C/gi, ',')
13+
}
14+
315
function stringifyQuery(query: Record<string, any>): string {
416
const parts: string[] = []
517
for (const key in query) {
@@ -8,15 +20,11 @@ function stringifyQuery(query: Record<string, any>): string {
820
if (Array.isArray(value)) {
921
for (const v of value) {
1022
if (v != null) {
11-
parts.push(
12-
`${encodeURIComponent(key)}=${encodeURIComponent(String(v)).replace(/%40/g, '@').replace(/%2F/gi, '/').replace(/%3A/gi, ':')}`,
13-
)
23+
parts.push(`${encodeURIComponent(key)}=${readableEncode(String(v))}`)
1424
}
1525
}
1626
} else {
17-
parts.push(
18-
`${encodeURIComponent(key)}=${encodeURIComponent(String(value)).replace(/%40/g, '@').replace(/%2F/gi, '/').replace(/%3A/gi, ':')}`,
19-
)
27+
parts.push(`${encodeURIComponent(key)}=${readableEncode(String(value))}`)
2028
}
2129
}
2230
return parts.join('&')

0 commit comments

Comments
 (0)