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

Invalid extra escape for URLs #1180

Closed
2 tasks done
Hamper opened this issue Apr 23, 2020 · 3 comments
Closed
2 tasks done

Invalid extra escape for URLs #1180

Hamper opened this issue Apr 23, 2020 · 3 comments

Comments

@Hamper
Copy link

Hamper commented Apr 23, 2020

Describe the bug

  • Node.js version: 12.16.2
  • OS & version: gentoo linux

Invalid extra escape for urls only in got v11, not in v10

Actual behavior

Got escapes some symbols like ~ in url but should not do this because some servers don't parse such escaped symbols

Expected behavior

Symbols in URLs like ~ must not be escaped

Code to reproduce

const got = require('got');
const testURL = 'https://example.com/?test=test~test';
console.log('RIGHT URL:\n%o\n', new URL(testURL));
(async ()=>{
    try{
        await got(testURL, {
            hooks: {
                beforeRequest: [
                    (options) => {
                        console.log('GOT URL:\n%o\n', options.url);
                    }
                ]
            }
        });
    }
    catch(e){
    }
})();

same result with new URL(testURL)) in got parameters

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

It's a bug in the Node.js implementation. Try using URLSearchParams. The URL is normalized according to the spec. If servers don't follow the spec then it's not our problem.

Duplicate of #1113

@Hamper
Copy link
Author

Hamper commented Apr 24, 2020

According to https://tools.ietf.org/html/rfc3986#section-2.3 tilde is unreserved and should not encoded by URI producers.

querystring.escape() - does not escape tilde
new URL() - does not escape tilde
encodeURIComponent() - does not escape tilde
encodeURI() - does not escape tilde
browsers - does not escape tilde, normalize %7E as ~ before sending
got 10 - does not escape tilde

got 11 escapes tilde but should not according to RFC

@szmarczak
Copy link
Collaborator

Got doesn't do this. It's the native URLSearchParams. And, according to the WHATWG implementation the behavior is correct (see the original issue). I'll open a Node.js issue.

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

No branches or pull requests

2 participants