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

New unstable 1.1.5 broke $location URL parsing #2860

Closed
martinstein opened this issue Jun 3, 2013 · 24 comments
Closed

New unstable 1.1.5 broke $location URL parsing #2860

martinstein opened this issue Jun 3, 2013 · 24 comments

Comments

@martinstein
Copy link

Since 1.1.5, the $location provider now appends a hash-part to the URL, which it shouldn't!

Using plunkr for the test-case was problematic because of window.location. So, here is a minimal test-case as code that demonstrates the issue. Simply create an html-file with this code. Notice the URL change at the end after opening the page!

EDIT as @jssebastian clarified below: Visiting page.html, with no use of angular routing but only depending on $location, causes an unwanted redirection to page.html#/page.html

Test-case:

<html ng-app>
    <body class="item-content" ng-controller="MyController">
    </body>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
    <script type="text/javascript">
        function MyController($scope, $location) {};
    </script>
</html>
@martinstein
Copy link
Author

The wrong behavior happens in LocationHashbangUrl in $$compose. The $$parse function assigns a value for this.$$path, which in turn causes this.$$url to be non-empty. Then, the $$absUrl will be changed! (which it shouldn't)

this.$$compose = function() {
    var search = toKeyValue(this.$$search),
        hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';

    this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
    this.$$absUrl = appBase + (this.$$url ? hashPrefix + this.$$url : '');
  };

@martinstein
Copy link
Author

I am quite sure that the problem was introduced in this commit: 58ef323

@michaelnatkin
Copy link

Yes, this is biting me too. (I raised it here: https://groups.google.com/forum/?fromgroups=#!topic/angular/dcfC4hfbUZs, no answer yet.)

@michaelnatkin
Copy link

See also #2833 - this the real source of the problem I believe.

@snostorm
Copy link

Just +1 the annoyance on this one. I had brought $location in to one little directive and the next thing you know my urls were getting all mangled upon pageload. In general our frontend angular uses don't use routeProvider or locationProvider, so the fact it was modifying the urls was quite annoying. Temporary fix: removed $location for window.location as it does what we need for now.

@basarat
Copy link
Contributor

basarat commented Jun 28, 2013

broken for us too

@alexgorbatchev
Copy link

👍 broke here as well... $location.path() is returning starting from the very last slash instead of the whole path. This affects route resolution, none of the routes match any more in my app. Have to roll back to 1.1.4

@petebacondarwin
Copy link
Contributor

Should be fixed in master.

On 30 June 2013 18:52, Alex Gorbatchev [email protected] wrote:

[image: 👍] broke here as well... $location.path() is returning the
starting from the very last slash instead of the whole path


Reply to this email directly or view it on GitHubhttps://github.com//issues/2860#issuecomment-20252139
.

@petebacondarwin
Copy link
Contributor

Can you give it a try?

@alexgorbatchev
Copy link

Good job guys, will give it a try!

@martinstein
Copy link
Author

@petebacondarwin I have tried the current master and it still seems to be broken. Can somebody else confirm this?

@petebacondarwin
Copy link
Contributor

Can you provide a running example?

Pete
...from my mobile.
On 4 Jul 2013 15:07, "Martin Stein" [email protected] wrote:

@petebacondarwin https://github.com/petebacondarwin I have tried the
current master and it still seems to be broken. Can somebody else confirm
this?


Reply to this email directly or view it on GitHubhttps://github.com//issues/2860#issuecomment-20478867
.

@martinstein
Copy link
Author

I think the minimal example at the top of this issue should still demonstrate the issue (it is difficult to provide a plunkr example due to the window.location aspect).

@martinstein
Copy link
Author

In which commit was the code regarding the bug fixed? Maybe I based my test on the wrong code...

@artjumble
Copy link

While not an exhaustive test, I did update and it seems to be fixed for me.

@petebacondarwin
Copy link
Contributor

Have a look at this PR: #2969

@michaelnatkin
Copy link

I still don't get the logic of this. It seems like it would be way better
for angular to only rewrite URLs it knows about in the router. This current
design simply doesn't play well with angular used in a heterogeneous
environment with relative but non-angular URLs on the same page.


Michael Natkin
CTO
http://ChefSteps.com http://chefsteps.com/

On Thu, Jul 4, 2013 at 11:28 AM, Pete Bacon Darwin <[email protected]

wrote:

Have a look at this PR: #2969#2969


Reply to this email directly or view it on GitHubhttps://github.com//issues/2860#issuecomment-20489124
.

@jssebastian
Copy link

@petebacondarwin: #2969 does not affect/fix this issue.

We're talking about use cases where html5 mode is off and the app is not hosted at "/". I just tested master (which includes the patch) in this scenario: behavior on the test above seems to be identical to behavior of 1.1.5 as far as I could see. The unwanted redirection does not trigger in either version if you set:

<base href="page.html/">

(where page.html is the page in the server root where I dumped the code above)... but that hardly ever makes sense in the context of a non-html5 app, and forces one to use absolute links to all assets, which breaks external code (e.g., jquery-ui) that does not do that.

@michaelnatkin
Copy link

> (where page.html is the page in the server root where I dumped the code above)... but that hardly ever makes sense in the context of a non-html5 app, and forces one to use absolute links to all assets, which breaks external code (e.g., jquery-ui) that does not do that.

precisely... I've had to just stop using $location b/c I can't live with
that restriction.


Michael Natkin
CTO
http://ChefSteps.com http://chefsteps.com/

On Fri, Jul 5, 2013 at 1:57 PM, jssebastian [email protected]:

@petebacondarwin https://github.com/petebacondarwin: #2969https://github.com/angular/angular.js/issues/2969does not affect/fix this issue.

We're talking about use cases where html5 mode is off and the app is not
hosted at "/". I just tested master (which includes the patch) in this
scenario: behavior on the test above seems to be identical to behavior of
1.1.5 as far as I could see. The unwanted redirection does not trigger in
either version if you set:

(where page.html is the page in the server root where I dumped the code
above)... but that hardly ever makes sense in the context of a non-html5
app, and forces one to use absolute links to all assets, which breaks
external code (e.g., jquery-ui) that does not do that.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2860#issuecomment-20538548
.

@martinstein
Copy link
Author

I agree with @jssebastian : #2969 does not fix this, since that pull request only concerns html5mode. But the problem here occurs in hashbangMode.

@jssebastian
Copy link

Just wanted to clarify, as no one has made it explicit in this thread. The issue is that visiting page.html, with no use of angular routing but only depending on $location, causes an unwanted redirection to page.html#/page.html.

@basarat
Copy link
Contributor

basarat commented Aug 1, 2013

Fixed for me. Put the following in my html head:

    <base href="/"/>

@wmayner
Copy link

wmayner commented Sep 30, 2013

👍

@jeffbcross
Copy link
Contributor

If this is still broken for anyone in 1.3 or 1.2 latest, feel free to reopen this issue with an updated plunker.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants