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

Use the same parse processing at contractor of URL with setters #1549

Merged
merged 4 commits into from
Jan 20, 2019

Conversation

watilde
Copy link
Contributor

@watilde watilde commented Jan 19, 2019

Problem this patch fixes

Currently, contractor of URL does not use the same parse processing with the setters in the Class and it makes inconsistent behaviour. See the code below and this patch is to fix the issue.

There is more missing implementation around ASCII encoding at URL and I'm working on it based on this patch. Let me know if you have any question.

Code to reproduce

const url = new URL('http:https://example.com/パス');
console.log(url.pathname);
// => /パス

url.pathname = 'パス';
console.log(url.pathname);
// => /%u30D1%u30B9

@CLAassistant
Copy link

CLAassistant commented Jan 19, 2019

CLA assistant check
All committers have signed the CLA.

@watilde watilde changed the title Use the same parse processing in contractor of URL with setters Use the same parse processing at contractor of URL with setters Jan 19, 2019
query: urlParts.query || baseParts.query,
hash: urlParts.hash
};
this._parts = initializedURLParts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? How is this related to the issue mentioned in the PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this means every instance of URL that does not have protocol, but has baseParts would share the same instance of this._parts which sounds very bad.

Copy link
Contributor Author

@watilde watilde Jan 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the beginning, I thought the same but turned out setter will refuse provided value if there is no initialized Object in _parts.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test in js/url_test.ts

@kitsonk
Copy link
Contributor

kitsonk commented Jan 19, 2019

URL in the browser returns the following, the test should match that:

const url = new URL('http:https://example.com/パス');
console.log(url.pathname);
// => /%E3%83%91%E3%82%B9

url.pathname = 'パス';
console.log(url.pathname);
// => /%E3%83%91%E3%82%B9

@watilde
Copy link
Contributor Author

watilde commented Jan 19, 2019

@kitsonk That's right. The punycode support is what I'd love to have eventually, but I'd prefer to take a small step to reach out to there. I'm wondering if it's ok to just wrap the official whatwg-url impl, then we do not need to run all WPT tests in this repository that we might need eventually since that module is already checked.

@watilde
Copy link
Contributor Author

watilde commented Jan 19, 2019

@kitsonk I opened a related issue at #1551. I'd appreciate if we can continue the disscussion at there :)

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks

@ry ry merged commit 9e1f5cc into denoland:master Jan 20, 2019
@watilde watilde deleted the fix/url branch January 20, 2019 19:09
@kitsonk
Copy link
Contributor

kitsonk commented Jan 20, 2019

@ry, @watilde this still has a problem... This comment was not addressed:

Also, this means every instance of URL that does not have protocol, but has baseParts would share the same instance of this._parts which sounds very bad.

I don't think this should have been merged. I am still missing the purpose of it, because in the constructor, the _parts will always be intiailised. I would have liked to seen a test that replicated the issue before we changed this. All this required was adding pathname to the intialisation object, instead of doing this. Also in the other part, where we intialise each property, upon reflection, it just needed pathname added as well.

Right now every instance of URL which has a basePath passed will share the same instance of parts, so a change to one of them will change them all... For example I bet this will break:

const a = new URL("/bar", "https://example.com/");
const b = new URL("/baz", "https://example.com/");

console.log(a.pathname); // "/baz"
console.log(b.pathname): // "/baz"

a.pathname = "/bar";

console.log(a.pathname); // "/bar"
console.log(b.pathname): // "/bar"

Can we please revert and fix the issue properly?

@ry
Copy link
Member

ry commented Jan 21, 2019

Oops! Sorry @kitsonk I was skimming - revert: #1556

ry added a commit to ry/deno that referenced this pull request Jan 21, 2019
…rs (denoland#1549)"

Right now every instance of URL which has a basePath passed will share
the same instance of parts, so a change to one of them will change them
all.

denoland#1549 (comment)

This reverts commit 9e1f5cc.
ry added a commit that referenced this pull request Jan 21, 2019
…rs (#1549)"

Right now every instance of URL which has a basePath passed will share
the same instance of parts, so a change to one of them will change them
all.

#1549 (comment)

This reverts commit 9e1f5cc.
Tzikas added a commit to Tzikas/squares that referenced this pull request Sep 10, 2019
…rs (#1549)"

Right now every instance of URL which has a basePath passed will share
the same instance of parts, so a change to one of them will change them
all.

denoland/deno#1549 (comment)

This reverts commit 9e1f5cc.
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

Successfully merging this pull request may close these issues.

None yet

4 participants