Skip to content

fix(common): Update Location to get a normalized URL valid in case a represented URL starts with the substring equals APP_BASE_HREF#48394

Closed
constantant wants to merge 1 commit intoangular:mainfrom
constantant:fix-common/45744
Closed

fix(common): Update Location to get a normalized URL valid in case a represented URL starts with the substring equals APP_BASE_HREF#48394
constantant wants to merge 1 commit intoangular:mainfrom
constantant:fix-common/45744

Conversation

@constantant
Copy link
Contributor

Update Location to get a normalized URL valid in case a represented URL starts with the substring equals APP_BASE_HREF

@NgModule({
  imports: [RouterModule.forRoot([{path: '/enigma', component: EnigmaComponent}])],
  providers: [{provide: APP_BASE_HREF, useValue: '/en'}]
})
export class AppModule {}

Navigating to /enigma will redirect to /en/igma not to /en/enigma as it expects

Fixes: #45744

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: 45744

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for taking this one on too :)

@atscott atscott added target: patch This PR is targeted for the next patch release action: global presubmit The PR is in need of a google3 global presubmit labels Dec 8, 2022
@jessicajaniuk jessicajaniuk added the area: common Issues related to APIs in the @angular/common package label Dec 9, 2022
@ngbot ngbot bot added this to the Backlog milestone Dec 9, 2022
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

Thnx for the fix!

I've left a small nit / cleanup comment, feel free to address or ignore.

@pkozlowski-opensource pkozlowski-opensource added action: merge The PR is ready for merge by the caretaker and removed action: global presubmit The PR is in need of a google3 global presubmit labels Dec 10, 2022
@ngbot
Copy link

ngbot bot commented Dec 10, 2022

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "google-internal-tests" is failing
    pending status "mergeability" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

…a represented URL starts with the substring equals `APP_BASE_HREF`

```ts
@NgModule({
  imports: [RouterModule.forRoot([{path: '/enigma', component: EnigmaComponent}])],
  providers: [{provide: APP_BASE_HREF, useValue: '/en'}]
})
export class AppModule {}
```

Navigating to `/enigma` will redirect to `/en/igma` not to `/en/enigma` as it expects

Fixes: angular#45744
@pkozlowski-opensource pkozlowski-opensource added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Dec 12, 2022
@pkozlowski-opensource
Copy link
Member

caretaker note: as far as I can tell the failing G3 check is pre-existing and not related to this change

@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit d87285c.

jessicajaniuk pushed a commit that referenced this pull request Dec 12, 2022
…a represented URL starts with the substring equals `APP_BASE_HREF` (#48394)

```ts
@NgModule({
  imports: [RouterModule.forRoot([{path: '/enigma', component: EnigmaComponent}])],
  providers: [{provide: APP_BASE_HREF, useValue: '/en'}]
})
export class AppModule {}
```

Navigating to `/enigma` will redirect to `/en/igma` not to `/en/enigma` as it expects

Fixes: #45744

PR Close #48394
@constantant constantant deleted the fix-common/45744 branch December 12, 2022 22:48
@jessicajaniuk
Copy link
Contributor

@constantant This caused a breakage in Google3 and had to be reverted in #48461.

@constantant
Copy link
Contributor Author

constantant commented Dec 13, 2022

@jessicajaniuk did you see the comment from @pkozlowski-opensource ?

@jessicajaniuk
Copy link
Contributor

@constantant That was pre-merge. Post-merge we got direct reports of multiple failures breaking tests and builds from those teams. So it actually isn't irrelevant. Reverting this fixed their broken test cases. Apps were unable to reach certain paths after this change landed. I'm doing a bit of investigating as to why.

@jessicajaniuk
Copy link
Contributor

@constantant OK, after a little bit of investigating, we've figured out the cause. When the URL has query params, matrix params, or fragments at the end, the check on line 304 in your PR fails to match up and moves to the second part, which duplicates the APP_BASE_HREF in the url. So what happens is something like this:

APP_BASE_HREF = '/pathA/pathB';

path: .../pathA/pathB?h=0
result: .../pathA/pathB/pathA/pathB?h=0

This would happen with query params, like above, or fragments, like pathA/pathB#id or matrix params, like pathA/pathB;a=1. If you can update to account for these cases, that'd be awesome.

@constantant
Copy link
Contributor Author

@jessicajaniuk I will take care of it. Thanks for explanation.

@constantant
Copy link
Contributor Author

@jessicajaniuk I have opened another PR: #48489

@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 Jan 14, 2023
trekladyone pushed a commit to trekladyone/angular that referenced this pull request Feb 1, 2023
…a represented URL starts with the substring equals `APP_BASE_HREF` (angular#48394)

```ts
@NgModule({
  imports: [RouterModule.forRoot([{path: '/enigma', component: EnigmaComponent}])],
  providers: [{provide: APP_BASE_HREF, useValue: '/en'}]
})
export class AppModule {}
```

Navigating to `/enigma` will redirect to `/en/igma` not to `/en/enigma` as it expects

Fixes: angular#45744

PR Close angular#48394
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: common Issues related to APIs in the @angular/common package merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

APP_BASE_HREF doesn't work with routes which starts with the same text part

4 participants