-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(core): cannot override properties with .
in the name
#10441
fix(core): cannot override properties with .
in the name
#10441
Conversation
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.
Can you also add a test for backslash escapes in other situations than preceding a .
?
Like, what should things like:
r.addOverride('Properties.The\\Back\\Slashes', 42);
r.addOverride('Properties.The\\\\Back\\\\Slashes', 42);
Evaluate to?
I've fixed the implementation and added some test cases to show the current range behaviors. To specify a property name that itself contains a period preceded by a backslash, you can do so by just adding extra backslashes in front. It's worth mentioning if you want a property name to end with a backslash, e.g.
that isn't doable, but I think something like this is inevitable with any escaping-based solution. The robust solution would be to change addOverride (or add a variation) that allows for passing in an array of strings. But I don't think there's currently need for that, so this fix should be good enough. |
What I meant here, which I didn't explain clearly enough (I'm sorry), is: usually, a I changed the processing logic a little to make it more general, to show you what I mean: the However, now having written that, I hate how the very obvious escape character is already escaped by the surrounding language, and so you end up having to write So now I wonder whether we shouldn't use a different escape character. "Microsoft escaping" (for lack of a better word) often doubles up the special character to escape it, so that would mean typing Thoughts? |
Ah, I see what you mean - yeah there was some ambiguity, but I think what you are suggesting where all backslashes escape strings makes sense, and it fixes the problem I mentioned which is great. I haven't seen the "Microsoft escaping" idea before, but I feel like that presents ambiguity because something like
Right, the leaning toothpick syndrome. To make it less verbose, we could write the tests with raw strings to make the behavior more clear (see below): r.addOverride('Properties.Hello\\.World.Foo\\.Bar\\.Baz', 42);
// ... replaced with ...
r.addOverride(String.raw`Properties.Hello\.World.Foo\.Bar\.Baz', 42); How does that sound? [Side note: I was thinking of where else this problem is seen, and I think CSV is probably the most familiar (as this format depends on having a way to escape commas) -- but I personally dislike the solution used there, since it requires wrapping the whole string instead of localizing it to the problem character. So my preference would be towards using backslashes.] |
I was not aware of |
We ultimately needed to use a function to scan through the string after all. Using a regex with a backreference won't work because that regex won't be able to tell the difference between:
It depends on whether the number of backslashes preceding the |
.
in them
.
in them.
in the name
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Closes #10109
While researching this, I saw some comments multiple years old saying that JavaScript doesn't support RegExp lookbehind assertions, but from the looks of https://node.green/ it is supported all the way back to 10.3.0, so that aligns with current CDK supported node versions.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license