-
Notifications
You must be signed in to change notification settings - Fork 27.3k
fix(ngResource): fix query url params encoding #12201
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
+1 to this fix, thanks @alediaferia |
src/ngResource/resource.js
Outdated
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.
You need the '(\\W|$)'
part or else you might get false positives. (Better yet '(?:\\W|$)'
.)
E.g. param: 'foo'
and url: '/path/foo?key=:foobar'
will lead to a false positive.
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.
I agree my regex is too broad but I'm not sure I completely get the one proposed by you.
Would something like the following be more accurate?
new RegExp("\\?((\\w+)\\=\\w+&)*\\w+=:" + param + "(\\W|$)").test(url)
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.
No need to make it too strict either :)
IMO, new RegExp('\\?(.*):' + param + '(\\W|$)')
(or new RegExp('\\?(?:.*):' + param + '(?:\\W|$)')
) is fine.
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.
So what does ?:
match exactly? This is the only bit I don't understand. :)
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.
Ooh, it's the non-capturing group! :)
fbd119c
to
dc1a67c
Compare
I've updated the code accordingly and split my commit messages to better comply with contribution guidelines. |
src/ngResource/resource.js
Outdated
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.
Nitpick: You don't need \\
before :
(it's not a special character in this context).
dc1a67c
to
cd4a591
Compare
LGTM |
1 similar comment
LGTM |
Is there a plan for when this will go in the main line? |
Bump! |
test/ngResource/resourceSpec.js
Outdated
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.
I'd prefer a more descriptive testcase name (e.g. should encode & in query params unless in query param value
or something).
@alediaferia, thx for the update. I left a couple of comments (mostly minor). |
@gkalpak BTW do you have any hint on why now my |
@alediaferia, no idea :) Does it happen with the code currently on the PR ? |
Sounds like something to do with the closure compiler? |
@gkalpak @petebacondarwin sorry for not getting back earlier. It's happening with the current PR but it's happening with updated master as well. It may be something wrong with my npm/node configuration, but not sure. I'm not much into JavaScript :) |
@alediaferia, (un)fortunately, I'm not getting any issues with |
test/ngResource/resourceSpec.js
Outdated
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.
I'm wondering if part of this test is a duplicate of the one preceding this test.
'should encode & in url params'
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.
I would say close but not quite.
I would be happy to have them merged into one it
block (keeping all 3 cases).
Feel free to merge them.
@gkalpak ping |
scripts/npm/install-dependencies.sh
Outdated
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.
I guess this has to do with your grunt package
issues, but it definitely does not belong in this PR :)
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.
Woops! sorry :)
Similar e2e tests assessing URL params encoding have been merged Dropped unwanted changes on install-dependencies.sh script
LGTM, thx @alediaferia ! /cc @petebacondarwin |
If this is ok, shall I clean up the git history squashing the latest commits and following your commit message conventions? |
OK, LGTM. @alediaferia thanks for your work on this. If you want to squash and tidy up the commit message that would be great. Otherwise, perhaps @gkalpak could do it when merging? |
Sure, I'll take care of squashing and merging ! |
Thank you @gkalpak @petebacondarwin |
@petebacondarwin, should this be backported to 1.4.x ? |
If you are confident it is not a breaking change. |
It's one of those times that I find it hard to distinguish between a fix and a BC. The only change introduced is when a param ( E.g., assuming 1.4.x: |
Although I feel the "new" behaviour is the right one I unfortunately think there may be a lot of apps out there relying on a workaround for this "issue". If you look for e.g. Just my 2 cents. Happy to have contributed to such a big project anyway :) |
OK, so no backport. |
@alediaferia, I couldn't find any SO questions/answers that would be broken by this "fix". Relying on a workaround isn't a problem (it won't get broken). The problem is if someone has as a URL template such as |
@gkalpak I cannot manage to find the question I had in mind, strange. Anyway, as you point out, relying on a workaround won't make things break. That's true. I don't have further objections. |
Encoding URL Query Parameters should be "more aggressive" than the URL Segment encoding.
You can see what I mean in the added test case.
I'm currently using AngularJS 1.3.16 but I found this bug is still there in master.