-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix (ngResource) dynamic params escaping fix #15627
Conversation
Added replacing of '%5c' (url encoded backslash) with \ (backslash) in Angular.js Added tests for this behavior in resourceSpec.js No breaking changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation-wise LGTM.
I am a little concerned about whether this is a breaking change, though. The docs are not clear on whether \.
in param values is expected to be escaped and there is the possibility that people rely on the current behavior.
@@ -594,7 +594,7 @@ angular.module('ngResource', ['ng']). | |||
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x` | |||
url = url.replace(/\/\.(?=\w+($|\?))/, '.'); | |||
// replace escaped `/\.` with `/.` | |||
config.url = protocolAndIpv6 + url.replace(/\/\\\./, '/.'); | |||
config.url = protocolAndIpv6 + url.replace(/\/(\\|%5C)\./, '/.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add a comment about how %5C
came to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Regarding the breaking change, thinking about it again the only usecase that would fail is the following (which is very unlikely): $resource('/foo/:bar', {bar: '\\.baz'})
// Request URL before: /foo/%5C.baz
// Request URL after: /foo/.baz And considering that So, this is a fix 🎉 |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix
What is the current behavior? (You can also link to an open issue here)
It doesn't work correctly according to docs if url params are dynamic. So, for instance, this is gonna work:
but almost the same code works incorrectly:
it sends request to
:path/%5C.json
Does this PR introduce a breaking change?
Might be
Please check if the PR fulfills these requirements
Other information: