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

fix(upgrade): fix AngularJsUrlCodec to support Safari #32959

Closed
wants to merge 1 commit into from
Closed

fix(upgrade): fix AngularJsUrlCodec to support Safari #32959

wants to merge 1 commit into from

Conversation

agale123
Copy link
Contributor

@agale123 agale123 commented Oct 2, 2019

Safari throws an error when the new URL() constructor is called with an
undefined base. This change checks whether the base is undefined and
then calls the corresponding version of the URL constructor.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #32874

What is the new behavior?

The AngularJsUrlCodec used by the $locationShim works in Safari.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@agale123 agale123 requested a review from a team as a code owner October 2, 2019 12:47
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @agale123!
I think the fix could be simpler but otherwise LGTM.

packages/common/upgrade/src/params.ts Outdated Show resolved Hide resolved
@trotyl
Copy link
Contributor

trotyl commented Oct 2, 2019

I don't think this is the right approach, URL constructor is part of the core-js polyfills, if Angular made use of it, then it should be a mandatory polyfill in Angular CLI, rather than asking every package to workaround it individually.

EDIT: May better be commented with notes like enable this when you use @angular/upgrade.

@petebacondarwin
Copy link
Member

@trotyl - I don't think that including this polyfill would solve the problem, unless I misunderstand how the polyfill would be applied. Safari supports URL and so my understanding is that the polyfill would not be applied. In which case we still have the problem.

@petebacondarwin
Copy link
Member

Or perhaps I am wrong and that applying the polyfill will always override the native URL? In which case that seems overkill for such a simple fix?

@trotyl
Copy link
Contributor

trotyl commented Oct 2, 2019

@petebacondarwin
Copy link
Member

There is no check for new URL('abc', undefined); in those tests though... 🤔

@trotyl
Copy link
Contributor

trotyl commented Oct 2, 2019

There is no check for new URL('abc', undefined); in those tests though... 🤔

@petebacondarwin It should be covered by all the single parameter cases like new URL('https://a@b').username !== 'a', if not supported this will throw an error and fail the whole test.

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes labels Oct 2, 2019
@petebacondarwin
Copy link
Member

petebacondarwin commented Oct 2, 2019

It should be covered by all the single parameter cases like new URL('https://a@b').username !== 'a',...

This is not the issue, passing only one parameter works. In fact this was @agale123 's original fix.
The problem is if you explicitly pass undefined as the 2nd argument.

@petebacondarwin
Copy link
Member

@agale123 could you rebase and squash all the commits into one please?

@petebacondarwin petebacondarwin added area: upgrade Issues related to AngularJS → Angular upgrade APIs target: patch This PR is targeted for the next patch release type: bug/fix labels Oct 2, 2019
@ngbot ngbot bot added this to the needsTriage milestone Oct 2, 2019
@agale123
Copy link
Contributor Author

agale123 commented Oct 2, 2019

@agale123 could you rebase and squash all the commits into one please?

Done.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

Thx, @agale123! One comment about the implementation, but the direction is right 😁
BTW, it would be great if we could add some tests for parse() (but not blocking since we didn't have explicit tests before).

packages/common/upgrade/src/params.ts Outdated Show resolved Hide resolved
Safari throws an error when the new URL() constructor is called with an
undefined base. This change checks whether the base is undefined and
then calls the corresponding version of the URL constructor.

fix(upgrade): simplify solution by replacing undefined with ''

Co-Authored-By: Pete Bacon Darwin <pete@bacondarwin.com>

Simplify solution by replacing undefined with ''

Co-Authored-By: Pete Bacon Darwin <pete@bacondarwin.com>

fix(upgrade): Avoid passing an empty string as the base as well.

Browsers other than Safari may have issues with the empty string.
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Oct 2, 2019
@agale123
Copy link
Contributor Author

agale123 commented Oct 2, 2019

ct

That's good to know, I'll go ahead and make that change.

@trotyl
Copy link
Contributor

trotyl commented Oct 2, 2019

@petebacondarwin Raised zloirock/core-js#656 for core-js issue tracking.

@gkalpak gkalpak added the action: merge The PR is ready for merge by the caretaker label Oct 2, 2019
@atscott
Copy link
Contributor

atscott commented Oct 2, 2019

Presubmit

atscott pushed a commit that referenced this pull request Oct 2, 2019
Safari throws an error when the new URL() constructor is called with an
undefined base. This change checks whether the base is undefined and
then calls the corresponding version of the URL constructor.

fix(upgrade): simplify solution by replacing undefined with ''

Co-Authored-By: Pete Bacon Darwin <pete@bacondarwin.com>

Simplify solution by replacing undefined with ''

Co-Authored-By: Pete Bacon Darwin <pete@bacondarwin.com>

fix(upgrade): Avoid passing an empty string as the base as well.

Browsers other than Safari may have issues with the empty string.

PR Close #32959
@atscott atscott closed this in 39e8ceb Oct 2, 2019
@agale123 agale123 deleted the url-codec branch October 2, 2019 17:14
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: upgrade Issues related to AngularJS → Angular upgrade APIs cla: yes target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants