X Tutup
Skip to content

Remove forward slashes and equal signs as delimiters in query parameter values#7312

Closed
AlexBachmann wants to merge 1 commit intoangular:masterfrom
AlexBachmann:url_parser_issue
Closed

Remove forward slashes and equal signs as delimiters in query parameter values#7312
AlexBachmann wants to merge 1 commit intoangular:masterfrom
AlexBachmann:url_parser_issue

Conversation

@AlexBachmann
Copy link
Copy Markdown

Right now, url query parameter values are matched using the matchUrlSegement method in the UrlParser. This method returns all characters of a string that are not classified as delimiters in the semgement regular expression SEGMENT_RE. One of the delimiters defined here is a forward slash, which makes sense, since the forward slash is a delimiter when it comes to segmenting the url path.

However, within url queries, a forward slash is allowed and should not be handled as a delimiter. The best real world example I can give is an oAuth2 request to Google, which returns an authorization code via url query parameters. The redirect_url called by Google could look something like this:

http://your-host.com/oauth2callback/googleanalytics?code=4/B8o0n_Y7XZTb-pVKBw5daZyGAUbMljyLf7uNgTy6ja8&scope=https://www.googleapis.com/auth/analytics#

Both, the authorization code and the scope parameter returned by Google contain forward slashes.
However, up until now, the url parser would parse the url and only recognize code=4 as a parameter and ignore the rest of the string, since the rest of the url string would not match the query string conventions.

This is a bug which is addressed with this pull request.

NOTE: I also removed the equals sign (=) from the query value delimiter list. I was not sure about the other delimiters "(" ")" ";" and "#". Maybe they can also be removed as delimiters for query parameter values, but I'm not sure here.

@AlexBachmann
Copy link
Copy Markdown
Author

I investigated the possiblity to remove the forward slash as a delimiter for matrix parameters as well, but this makes no sense, since this goes against the idea of using matrix paramters within the path segements themselves:

http://host.com/path1;a=2/path2;b=3

So the forward slash needs to remain a delimiter for matrix parameters.
This conflicts with the issue #7314, which describes that angular right now takes any parameters of the url and appends them as matrix parameters AND query parameters. As soon as a parameter contains a forward slash, as in an oauth request described above, angular breaks, since the created matrix parameter containing the forward slash breaks the segment parsing of the UrlParser.

I propose tackeling #7314 first,and this one afterwards.

@SonofNun15
Copy link
Copy Markdown

👍 Ran into this same issue today with implementing authentication via an OAuth2 request to Google today and I can't use RouteParams to get the access code because of this issue. I'll have to use window.location.search for now, as much as it pains me to do so...

@naomiblack
Copy link
Copy Markdown
Contributor

this looks promising, sending to @btford for review

@btford
Copy link
Copy Markdown
Contributor

btford commented Mar 29, 2016

Looks good, just doesn't pass lint.

@naomiblack
Copy link
Copy Markdown
Contributor

Thanks! Closing this PR as #7824 fixes the linting issues and includes all its changes.

@johnzangwill
Copy link
Copy Markdown

Same problem with brackets. Even if I escape them, the parameter value gets truncated at the first bracket. I am having to convert them to a completely different character and then convert them back afterwards. (I am using HashLocationStrategy, which may or may not be relevant)

@angular-automatic-lock-bot
Copy link
Copy Markdown

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 Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup