workers-sdk: 🐛 BUG: wrangler2 can not decode `[` and `]`

What version of Wrangler are you using?

2.0.16

What operating system are you using?

Mac

Describe the Bug

Description

When I serve my next app statically with wrangler pages dev out, I believe wrangler is failing to decode [id] and throwing me a 404 error. When I examine the network tab of the developer console, I see that the failing request is to %5Bid%5D. However the same request results with a 200 response on Cloudflare Pages. Also if I edit the failing GET request by replacing the %5B and %5D with [ and ], I get a 200 response. I believe there is something wrong with the decoding of [ and ]. image

Steps to Reproduce

  • Create a next app with yarn create next app pages-example
  • Add "export": "next export" to package.json
  • create a directory under /pages named p and create an empty [id].js file.
  • fill the file with the following content
    import React  from 'react';
    import { useRouter } from 'next/router';
    
    const Page = () => {
        const router = useRouter();
    
        const { id } = router.query;
    
        console.log(id, router);
        return (
      	  <div>
      		  id from url: { id } 
      	  </div>
        );
    };
    
    export default Page;
    
  • create a /functions/p/[id].js with the following content
    export function onRequestGet({ env, request, params }) {
      console.log("entering the function")
      console.log("env", env)
      console.log("request", request)
      return env.ASSETS.fetch(new Request(new URL('/p/[id]', request.url).toString(), request));
    }
    
    
  • run yarn build && yarn export
  • run wrangler pages dev out
  • type http://localhost:8788/p/12 to the address bar.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (6 by maintainers)

Most upvoted comments

I’ll have a look into resolving that in the morning 🙂

@Skye-31 I can test it tomorrow and let you know!

I’m unsure but I have a feeling that https://github.com/cloudflare/wrangler2/pull/1431 might resolve this. @GregBrimble Can you confirm?

Thanks for the bug report in the mean time. This is certainly a bug indeed.