Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polka interprets percent-encoded slashes the same as regular slashes #142

Open
tiffany352 opened this issue Aug 30, 2020 · 1 comment
Open
Labels

Comments

@tiffany352
Copy link

tiffany352 commented Aug 30, 2020

I have an app with a query endpoint like /query/:input and sometimes the input can be something like 1/7.

I would have a url like /query/1%20%2F%207 (percent encoded 1 / 7) and end up getting a 404 page. I added a console.log call and it turned out this was being decoded into /query/1 / 7 in request.url. Express doesn't have this issue, for comparison.

I was using the next version from NPM because that was the default in the Sapper template.

Repro

const polka = require("polka");

polka()
  .use((req, res, next) => {
    console.log("url", req.url);
    next();
  })
  .get("/query/:input", (req, res) => {
    res.end(
      JSON.stringify({
        url: req.url,
        input: req.params.input,
      })
    );
  })
  .listen(3000, (err) => {
    if (err) throw err;
    console.log("> Running on localhost:3000");
  });
$ curl http://localhost:3000/query/1%20%2F%207

Expected behavior / Express behavior

200 OK with body:

{
  "url": "/query/1%20%2F%207",
  "input": "1 / 7"
}

Actual behavior (5.2.0)

200 OK with body:

{
  "url": "/query/1%20%2F%207",
  "input": "1%20%2F%207"
}

(input is urlencoded when it should be decoded)

Actual behavior (next)

Server prints url /query/1 / 7.

Curl sees 404 Not Found.

@benmccann
Copy link

I hit this as well. I think that Polka should go back to the 0.x behavior for URL parsing. I don't want Polka to touch my URL at all but just pass along what was received. Netlify tried to decode just as Polka 1.x was trying and they decided it was a bad idea and had to revert the change just as I think we should here as well: https://answers.netlify.com/t/bug-fix-url-encoding-preserved-in-function-event/27080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants