Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

bug($location): incorrect URL parsing when (1) angular app lives under a subdirectory (2) HTML5 routing is off and (3) there's no trailing slash when accessing app root #2833

@chibicode

Description

@chibicode

Suppose you turned off HTML5 routing and your app lives at

http://localhost:5000/angular-app/

On version 1.1.5, if you navigate instead to a URL with no trailing slash, e.g.

http://localhost:5000/angular-app

then it redirects to:

http://localhost:5000/angular-app/#angular-app

I tracked down the problem - it's on this line:
https://github.com/angular/angular.js/blob/v1.1.5/src/ng/location.js#L158

  • If there's trailing slash (i.e. http://localhost:5000/angular-app/), beginsWith(appBase, url) returns /. So withoutBaseUrl is set as /.
  • However, if there's no trailing slash (i.e. http://localhost:5000/angular-app), beginsWith(appBase, url) returns an empty string, and it evaluates beginsWith(appBaseNoFile, url), which returns angular-app. So withoutBaseUrl is set as angular-app.

As a result, when HTML5 route is off, this.$$parse behaves differently for http://localhost:5000/angular-app (no trailing slash) and http://localhost:5000/angular-app/ (trailing slash), even though they should return the same thing.

The change is introduced on this commit (cc @mhevery) 58ef323

This is not a problem when (1) HTML5 routing is on (e.g. $locationProvider.html5Mode(true).hashPrefix('!')) and (2) <base href="/angular-app/" is added to <head>.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions