AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Dynamic Route Unhandled URIError For Malformed Percent Encoding (%A0) Causes 500 In Production

Next.js dynamic routes throw an unhandled URIError when a segment contains an invalid percent-encoded sequence like %A0, resulting in a 400 error in dev and a 500 error in production, generating unnecessary error-logging noise.

highConfidence 90%Next.jsApp Routernext buildAffected V16.2.1-Canary.26

Origin Analysis

Next.js internally uses decodeURIComponent on dynamic route parameters without a try/catch block. Malformed percent sequences (e.g., %A0) throw a URIError, which is not handled, causing an unhandled exception and a 500 response in production.
1. Create a Next.js app with a dynamic route (e.g., app/foo/[slug]/page.tsx). 2. Build and start the production server. 3. Navigate to /foo/bar%A0. 4. Observe a 500 error in production and a 400 error in dev.

Fixing Code Block

Edge Case Audit

This is a workaround, not an upstream fix. It issues a 308 redirect for any URL with invalid percent encoding, which may affect client behavior and SEO. If a malformed segment also contains valid percent-encoded characters, those will be double-encoded (e.g., %20 becomes %2520). Test thoroughly and remove this middleware once Next.js ships a native safe decode. If Next.js changes middleware execution order, this may not intercept before param decoding.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state