balazsbotond / urlcat

A URL builder library for JavaScript.
https://urlcat.org
MIT License
1.82k stars 57 forks source link

TypeError: Failed to construct 'URL': Argument 1 is not a valid ByteString #168

Closed cryptogohan closed 1 year ago

cryptogohan commented 3 years ago

Describe the bug I build a URL like so:

urlcat("https://twitter.com", "/i/api/2/search/adaptive.json", {
    q: query,
    tweet_search_mode: "live",
    // seems to respect numbers <100, seems to only go up to 104??
    count: 100,
});

Where query is "πŸ¦‡πŸ”Š", and get the following error:

TypeError: Failed to construct 'URL': Argument 1 is not a valid ByteString
    at makeException (deno:extensions/webidl/00_webidl.js:14:12)
    at converters.ByteString (deno:extensions/webidl/00_webidl.js:324:15)
    at Array.record<ByteString, ByteString> (deno:extensions/webidl/00_webidl.js:778:30)
    at Array.webidl.converters.sequence<sequence<USVString>> or record<USVString, USVString> or USVString (deno:extensions/url/00_url.js:529:67)
    at new URLSearchParams (deno:extensions/url/00_url.js:18:87)
    at query (https://deno.land/x/urlcat@v2.0.4/src/index.ts:95:10)
    at urlcatImpl (https://deno.land/x/urlcat@v2.0.4/src/index.ts:74:25)
    at urlcat (https://deno.land/x/urlcat@v2.0.4/src/index.ts:63:12)
    at makeSearchLatestUrl (file:///Users/alextes/code/twitter_scraper/src/twitter_web.ts:178:3)
    at file:///Users/alextes/code/twitter_scraper/src/twitter_web.ts:191:13

Encoding with encodeURIComponent seems to fix things but I thought the lib already did that for me? I'm also not sure why this started breaking one day to the next πŸ€” .

Thought I'd report, maybe it was always broken somehow and you do need to encode emoji yourself?

balazsbotond commented 2 years ago

@cryptogohan I couldn't reproduce this - worked perfectly for me:

https://twitter.com/i/api/2/search/adaptive.json?q=%F0%9F%A6%87%F0%9F%94%8A&tweet_search_mode=live&count=100

I'm using Node 16, maybe this only fails on earlier Node versions. I know this is an old bug but I would appreciate if you helped me reproduce it.

alextes commented 2 years ago

@cryptogohan is an alt I used for a short time.

Mmm, I'm not sure now. The code above is not running anymore. If I had to guess, it had something to do with the difference between Deno and Node. The above was running with Deno.

I'd say we can close this then.

balazsbotond commented 1 year ago

@alextes thanks checking it, I'm closing the issue.