# A request parameter error occurred in Edge Functions, which was normal before

**URL:** <https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893>\
**Category:** Support\
**Tags:** edge\_functions\
**Created:** [February 20, 2024, 9:24pm UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893 "2024-02-20T21:24:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![skw](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@skw](https://answers.netlify.com/u/skw)\
**Post date:** [February 20, 2024, 9:24pm UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/1 "2024-02-20T21:24:00Z")

</div>

Edge Function:

```js
export default req => new Response(new URL(req.url).search.substring(1))
export const config = { path: "/url-edge" }

```

Example:

```auto
https://testfunc.netlify.app/url-edge?p1=a%3D1%26b%3D2&p2=a%3D3%26b%3D4

```

Normal before `p1=a%3D1%26b%3D2&p2=a%3D3%26b%3D4`  
Parsed:

```js
console.log(...new URLSearchParams('p1=a%3D1%26b%3D2&p2=a%3D3%26b%3D4'))
// ['p1', 'a=1&b=2'] ['p2', 'a=3&b=4']

```

Now it becomes `p1=a=1&b=2&p2=a=3&b=4`  
Parsed:

```js
console.log(...new URLSearchParams('p1=a=1&b=2&p2=a=3&b=4'))
// ['p1', 'a=1'] ['b', '2'] ['p2', 'a=3'] ['b', '4']

```

My guess is that the employee wanted to fix [this problem](https://answers.netlify.com/t/dont-reorder-request-parameters-in-edge-functions/110490) but made a mistake.

---

<div class="post-metadata">

**Author:** ![dig](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dig/32/56744_2.png) [@dig](https://answers.netlify.com/u/dig)\
**Post date:** [February 20, 2024, 9:31pm UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/2 "2024-02-20T21:31:09Z")

</div>

You will see the same results using _Developer Tools_ in Firefox or Opera so this (IMHO) is nothing to do with Edge Functions but [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) itself.

Why are you using encoded strings in the first place?

---

<div class="post-metadata">

**Author:** ![skw](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@skw](https://answers.netlify.com/u/skw)\
**Post date:** [February 20, 2024, 10:12pm UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/3 "2024-02-20T22:12:50Z")

</div>

I mean `https://testfunc.netlify.app/url-edge?p1=a%3D1%26b%3D2&p2=a%3D3%26b%3D4` Edge Function should receive `['p1', 'a=1&b=2'] ['p2', 'a=3&b=4']`, but actually receives `['p1', 'a=1'] [' b', '2'] ['p2', 'a=3'] ['b', '4']`

Another example: ` https://testfunc.netlify.app/url-edge?api=https%3A%2F%2Fhttpbin.org%2Fget%3Fname%3Djohn%26gender%3D1%26age%3D22`

The parameter `api` is `https://httpbin.org/get?name=john&gender=1&age=22`, but it becomes `https://httpbin.org/get?name=john` in Edge Functions.

---

<div class="post-metadata">

**Author:** ![dig](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dig/32/56744_2.png) [@dig](https://answers.netlify.com/u/dig)\
**Post date:** [February 20, 2024, 10:32pm UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/4 "2024-02-20T22:32:15Z")

</div>

Why are you using `new URL(req.url).search.substring(1)`? Are you parsing the value of this? Why aren’t you using `new URL(req.url).searchParams`?

Either this is a very unique problem for a very unique use case (as [previously mentioned](https://answers.netlify.com/t/dont-reorder-request-parameters-in-edge-functions/110490/19)) or your usage of Web APIs is _back-to-front_, _upside-down_ and _inside-out_ and without seeing the code and understanding what you are doing with it, it is near impossible to provide a solution.

---

<div class="post-metadata">

**Author:** ![skw](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@skw](https://answers.netlify.com/u/skw)\
**Post date:** [February 20, 2024, 10:46pm UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/5 "2024-02-20T22:46:54Z")

</div>

I tested it, same result

```js
export default req => {
  const params = new URL(req.url).searchParams
  for (const [key, value] of params) {
    console.log(key, value)
  }
  return new Response('ok')
}
export const config = { path: "/log-params" }

```

```auto
https://testfunc.netlify.app/log-params?p1=a%3D1%26b%3D2&p2=a%3D3%26b%3D4

info [logParams] p1 a=1
info [logParams] b 2
info [logParams] p2 a=3
info [logParams] b 4

```

```auto
https://testfunc.netlify.app/log-params?api=https%3A%2F%2Fhttpbin.org%2Fget%3Fname%3Djohn%26gender%3D1%26age%3D22

info [logParams] api https://httpbin.org/get?name=john
info [logParams] gender 1
info [logParams] age 22

```

---

<div class="post-metadata">

**Author:** ![dig](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dig/32/56744_2.png) [@dig](https://answers.netlify.com/u/dig)\
**Post date:** [February 20, 2024, 11:33pm UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/6 "2024-02-20T23:33:32Z")

</div>

When I test your code locally (`ntl dev` using `localhost:8888` in place of `testfunc.netlify.app`)

> [@skw](#):
>
> `https://testfunc.netlify.app/log-params?p1=a%3D1%26b%3D2&p2=a%3D3%26b%3D4`

outputs

```auto
[log-params] p1 a=1&b=2
[log-params] p2 a=3&b=4

```

and

> [@skw](#):
>
> `https://testfunc.netlify.app/log-params?api=https%3A%2F%2Fhttpbin.org%2Fget%3Fname%3Djohn%26gender%3D1%26age%3D22`

outputs

```auto
[log-params] api https://httpbin.org/get?name=john&gender=1&age=22

```

Do you get the same _(I assume correct)_ results when testing locally and different _(I assume incorrect)_ results when deployed to Netlify? Or do you get the same results either way?

---

<div class="post-metadata">

**Author:** ![skw](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@skw](https://answers.netlify.com/u/skw)\
**Post date:** [February 21, 2024, 4:40am UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/7 "2024-02-21T04:40:07Z")

</div>

Yes, it is correct when `netlify dev` locally, but not correct when deployed to Netlify.

---

<div class="post-metadata">

**Author:** ![skn0tt](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/skn0tt/32/33874_2.png) [@skn0tt](https://answers.netlify.com/u/skn0tt)\
**Post date:** [February 23, 2024, 8:38am UTC](https://answers.netlify.com/t/a-request-parameter-error-occurred-in-edge-functions-which-was-normal-before/112893/9 "2024-02-23T08:38:34Z")

</div>

Hey folks, thanks for reporting this issue! Your hunch was right, this was related to a fix for [Don't reorder request parameters in Edge Functions](https://answers.netlify.com/t/dont-reorder-request-parameters-in-edge-functions/110490). I’ve rolled back the fix because it was causing some minor issues, and your argument also makes sense to me. The main point in RFC3986 that we need to adhere to is this:

> Percent-encoding a reserved character, or decoding a percent-encoded octet that corresponds to a reserved character, will change how the URI is interpreted by most applications. Thus, characters in the reserved set are protected from normalization and are therefore safe to be used by scheme-specific and producer-specific algorithms for delimiting data subcomponents within a URI.  
> ~ § 2.2 Reserved Characters

You should be seeing the same behaviour across production and netlify dev again on this now.
