Skip to content

[Router Core] Search Params errors when using % #4067

@TisRyno

Description

@TisRyno

Which project does this relate to?

Router

Describe the bug

The latest update in the router-core package, notably this commit 30c49e1

Has introduced an issue whenever search parameters are decoded that contain a % symbol in them.

The minimal reproduction will error the webpage on load with

Uncaught URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at toValue (chunk-PN7QCDU3.js?v=1cb8d5e8:862:41)
    at chunk-PN7QCDU3.js?v=1cb8d5e8:874:18
    at Array.reduce (<anonymous>)
    at decode (chunk-PN7QCDU3.js?v=1cb8d5e8:871:18)
    at Object.parseSearch (chunk-PN7QCDU3.js?v=1cb8d5e8:893:19)
    at parse (chunk-PN7QCDU3.js?v=1cb8d5e8:1598:43)
    at RouterCore.parseLocation (chunk-PN7QCDU3.js?v=1cb8d5e8:1609:24)
    at RouterCore.update (chunk-PN7QCDU3.js?v=1cb8d5e8:1465:36)
    at new RouterCore (chunk-PN7QCDU3.js?v=1cb8d5e8:2805:10)

The issue is due to the use of new URLSearchParams which will parse from testString=%25ba => ['testString', '%ba'] and is then sent onto the toValue method which uses the RegEx to look for any non-decoded characters, and then runs the decodeURIComponent method on a non-valid URI

Your Example Website or App

http://localhost:5173/?testString=%25ba

Steps to Reproduce the Bug or Issue

  1. npx create-tsrouter-app@latest my-app --template file-router
  2. npm run dev
  3. Open URL
  4. Page won't load

Expected behavior

Expect the page to load

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome/Safari/Firefox
  • Version: 1.117.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions