Skip to content
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
8 changes: 2 additions & 6 deletions packages/router-core/src/qss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* (namely URLSearchParams) and TypeScript while still
* maintaining the original functionality and interface.
*/
import { hasUriEncodedChars } from './utils'

/**
* Encodes an object into a query string.
Expand Down Expand Up @@ -42,11 +41,8 @@ export function encode(obj: any, pfx?: string) {
* // Example input: toValue("123")
* // Expected output: 123
*/
function toValue(mix: any) {
if (!mix) return ''
const str = hasUriEncodedChars(mix)
? decodeURIComponent(mix)
: decodeURIComponent(encodeURIComponent(mix))
function toValue(str: unknown) {
if (!str) return ''

if (str === 'false') return false
if (str === 'true') return true
Expand Down
17 changes: 0 additions & 17 deletions packages/router-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,20 +446,3 @@ export function shallow<T>(objA: T, objB: T) {
}
return true
}

/**
* Checks if a string contains URI-encoded special characters (e.g., %3F, %20).
*
* @param {string} inputString The string to check.
* @returns {boolean} True if the string contains URI-encoded characters, false otherwise.
* @example
* ```typescript
* const str1 = "foo%3Fbar";
* const hasEncodedChars = hasUriEncodedChars(str1); // returns true
* ```
*/
export function hasUriEncodedChars(inputString: string): boolean {
// This regex looks for a percent sign followed by two hexadecimal digits
const pattern = /%[0-9A-Fa-f]{2}/
return pattern.test(inputString)
}
6 changes: 6 additions & 0 deletions packages/router-core/tests/qss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ describe('decode function', () => {
const decodedObj = decode(queryString)
expect(decodedObj).toEqual({ q: 'red+yellow orange' })
})

it('should decode once percent characters (%) encoded twice', () => {
const queryString = 'q=%2540'
const decodedObj = decode(queryString)
expect(decodedObj).toEqual({ q: '%40' })
})
})