-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Escaping dot should be taken in deep property #402
Escaping dot should be taken in deep property #402
Conversation
* removing backslash prior to "." * test case: "foo\\.bar" names {"foo.bar": "baz"}
Thanks for the PR @umireon! While it does strictly break backwards compatibility - I'd be shocked if anyone was bitten by this - so I'm on the fence whether or not to merge it here or wait for 3.x.x. Having said that - as you mentioned, trying to escape results in wild behaviour so likely if people have seen this, they've seen bugged out behaviour - so I'd consider this a bug fix. Irregardless, a few notes:
|
This commit includes: * getPathInfo handles escaping `.[]` * Documentation added to `.property` * Documentation added to `.getPathInfo` * Test cases for `.property` * Test cases for `.deep.property` * Test cases for `.getPathInfo` Note that the input of `.getPathInfo` assumed to match the following: /^(?:(?:\\[.\[\]]|[^.\[\]])+|\[\d+\])(?:\.(?:\\[.\[\]]|[^.\[\]])+|\[\d+\])$/
Hi, @keithamus ! In fact, the path strings which the current implementation of I'm looking forward to hearing from you, |
var re = /(?:\\[.\[\]]|[^.\[\]])+|\[(\d+)\]/g | ||
, parsed = [] | ||
, value; | ||
while ((value = re.exec(path)) !== null) { |
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 need to use while
instead of Array#map
to avoid matching /[(\d+)]/ twice.
Well, |
I'm sorry if I didn't get your point, but you mean it would be nice to implement |
Pretty much yes. The regexp seems a little complex - and unless I'm mistaken a fair chunk of the complexity comes from detecting Please correct me if I'm wrong though. |
Frankly speaking, I'm not confident to keep the behavior unchanged with parsing the regular language (= the simple syntax of |
@@ -61,13 +62,13 @@ module.exports = function getPathInfo(path, obj) { | |||
*/ | |||
|
|||
function parsePath (path) { | |||
var str = path.replace(/\[/g, '.[') | |||
var str = path.replace(/([^\\])\[/g, '$1.[') |
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.
Without (([^\\])
, $1
), a\\[
results in accessing a.[
.
Actually, |
The expression was complex simply because three regular expressions and memory rewriting were combined. |
@umireon that now looks much clearer to me. Good job 😄 I'd like to pester you for one more bit:
Once that's done I'm happy to wrap up this PR 😄 |
@keithamus I've made it done! |
Great work @umireon! 🎉 |
Escaping dot should be taken in deep property
Linking #398 |
According to getPathInfo.js,
deep.property(name)
is assumed to support escaping dot.
by prepending backslash\
. However, escaping dot indeep.property
seems to work in the unexpected way. Here is the example:The current implementation of
deep.property
never match{"foo\\.bar": "baz"}
because backslash\
is not removed on processing escape. This PR fixes this problem. In addition, it includes the test case to ensure the problem fixed.Noted that this PR obviously breaks some backward compatibility.