Worker fails if incorrectly encoded % is in the URL

Hi,

We have some google search console errors turning up for URLs that have an incorrectly encoded % in the URL. As a worker handles each request for our site, we tried to handle these errors but it is not possible if the URL contains an incorrectly encoded % in the url.

The error can be reproduced by creating the following worker:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  return new Response('Website is working');	
}

And trying the following URLs in the preview:
https://www.cloudflare.com/test - works
https://www.cloudflare.com/test%20 - works
https://www.cloudflare.com/test%20test - works
https://www.cloudflare.com/test% - Throws Error 1101
https://www.cloudflare.com/test%D - Throws Error 1101

I also tried catching the error and logging it, but the editor fails to log the error so I can’t debug it more:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  try {
    return new Response('Website is working (try)');	
  } catch (e) {
    console.log(e);
    return new Response('Whoops! the website is down. :( 500 Internal Server Error. '+e.name, { status: 500, statusText: 'Internal Server Error' });
  }
}

The above code shows the same Error1101

Is someone able to let me know if there is a work around for this, or what we should do next?

Hi @michael42,

This turned out to be a bug in the preview itself, not in Workers – if you were to deploy the script, it would have worked fine in production. I have fixed the bug in the preview, so now it should work. Let me know if you still have trouble.

2 Likes

Thanks @KentonVarda, preview works now :slight_smile: