-
Notifications
You must be signed in to change notification settings - Fork 27.4k
LocationHtml5Url search() returns undefined if server rewrites base URL #11223
Comments
Ok, I dug a little deeper, and I think I can answer my own question. According to the RFC3986 standard, every part of a URL except the scheme and host are case-sensitive, including the part of the path that makes up the HTML5 Base URL. from http://tools.ietf.org/html/rfc3986#section-6.2.2.1:
Given this, if a non-normalized version of the base URL is requested, the best option is to have the server return a 301 redirect to the normalized version. That way you can ensure your href always matches the url requested, and the response will be cacheable. If that's not an option, I think the best solution is to replace this line in $LocationProvider's $get method:
with this:
This handles the case where the base URL and the base part of the requested URL only vary by case, which seems like a common case. If this is the canonical URL:
with a
and the user requests
this this will replace the base part of the url with the normalized version, and pass that to $$parseLinkUrl, which will correctly identify that the url beginsWith appBase, and will set rewrittenUrl to the remaining portion If this code is in the $LocationProvider's It doesn't overwrite initialUrl directly, because of the check later on in the $get function that rewrites the browser URL
If initialUrl is changed before this, then the absUrl and initialUrl will already match, and it won't update the browser's URL bar to match. Supporting anything more than a case-insensitive base URL seems prone to error, as there would be no way to determine where a non-normalized base URL ends and appURL begins. |
Since the relevant parts of the URL are case-sensitive, I don't think it makes sense to threat them as case-insensitive. If the spec says something is case-sensitive, then different casing designates a different thing and servers should treat such changes accordingly. I wouldn't be surprised if treating the baseHref case-insensitively would even have security implications. Closing as won't fix. |
Hi,
I encountered a problem where if the server rewrites part of the baseHref, the LocationHtml5Url $location.search() will return undefined, instead of an empty object.
For example, if I request:
http://www.example.com/Username
and the server rewrites it as
http://www.example.com/username
when the LocationProvider.$get calls $$parseLinkUrl, it doesn't call $$parse like it normally would, which would call parseAppUrl and set locationObj.$$search.
Since $$parseLinkUrl is comparing the rewritten appBase (
http://www.example.com/username
) against the requested initialUrl (http://www.example.com/Username
), the beginsWith check fails and it doesn't follow the same code path as if the url hadn't been rewritten.I can't say I'm familiar enough with the code to suggest a fix, but it seems like parseAppUrl sets up important state for the $location service, and not calling it during instantiation causes problems.
EDIT: forgot to mention, I encountered this running angular-1.3.6.js.
The text was updated successfully, but these errors were encountered: