-
Notifications
You must be signed in to change notification settings - Fork 2k
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 backslash in environment key freeze app [INS-4157] #7763
Fix backslash in environment key freeze app [INS-4157] #7763
Conversation
return objectPath.normalize(prefix); | ||
// objectPath.normalize will enter endless loop if last char in key name is backslash, just remove backslashes at the end of key name | ||
// workaround for https://github.com/Kong/insomnia/issues/7286 | ||
return objectPath.normalize(prefix.replace(/\\+']/g, '\']')); |
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.
(EDIT)
Maybe we prevent users from entering the backslash altogether
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 think this is OK as is.
There's more options:
- we could prevent users inputting backslash
- or delete it from the keys when saving environment
- or we display an error and don't save environment, like when we forget a , or a " on json, not allowing users to save environment until they delete \ present in keys
- or we keep your approach as is, and accept this as lesser evil - between crashing the app and leaving environment key dangling, this is good enough for now
- something else?
Could this be done without using a regex, would it be more readable? |
…/github.com/Kong/insomnia into fix/backslash-in-environment-key-freeze-app
…/github.com/Kong/insomnia into fix/backslash-in-environment-key-freeze-app
…/github.com/Kong/insomnia into fix/backslash-in-environment-key-freeze-app
…), remove duplicated file
This problem is caused by objectpath library, in its parse function, it could enter endless loop when the last char in key is backslash. It seems to be no longer maintained. |
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.
this looks like it would work, but a step deeper would be attempting to eliminate the library completely and just reimplement the two functions use cases with less code, and eliminate the while loop that causes the problem. Not required for me to approve this PR but worth considering if you like a challenge. 🎸
EDIT: Actually there are two things that could push you a little to improve this PR
- write a couple unit tests for forceBracketNotation and normalizeToDotAndBracketNotation
- attempt to simplify the object path implementation in the pr
I need some time to familiarize myself with Vitest. I just merged this PR, I'll improve in other threads. |
Close #7286
objectPath.normalize will enter endless loop if last char in key name is backslash, just remove backslashes at the end of key name.
It's just a workaround. It will introduce problems when reference an environment variable which's name ends with backslash.