awslabs / llrt

LLRT (Low Latency Runtime) is an experimental, lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.
Apache License 2.0
7.74k stars 342 forks source link

URL to_string bug #320

Closed gc-victor closed 3 months ago

gc-victor commented 3 months ago

In the URL to_string method, there is a bug in line 115:

https://github.com/awslabs/llrt/blob/808084b8cbef50218be3a17b110e8c438490e013/src/http/url.rs#L115

Should be:

&self.protocol, user_info, &self.hostname, port, &self.pathname, &search, &hash

Should be changed &self.host by &self.hostname.

Reference: https://developer.mozilla.org/en-US/docs/Web/API/URL/host https://developer.mozilla.org/en-US/docs/Web/API/URL/hostname

richarddavison commented 3 months ago

Thanks! I see that port should also not be included if it's the protocols default port. Taking a look

gc-victor commented 3 months ago

You are right!

I have checked it again and I think the best option should be:

&self.protocol, user_info, &self.host, &self.pathname, &search, &hash

Either option will work, but using "host", the "port" part of the function adding the ":" can be removed.

Example:

const url = new URL("https://developer.mozilla.org:443/en-US/docs/Web/API/URL/host");
console.log(url.toString()) // https://developer.mozilla.org/en-US/docs/Web/API/URL/host
console.log(url.host) // developer.mozilla.org
console.log(url.port) // empty-string

References: https://developer.mozilla.org/en-US/docs/Web/API/URL/toString https://url.spec.whatwg.org/#url-serializing https://url.spec.whatwg.org/#url-miscellaneous