Skip to content
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

Environment Variable Separation logic #14

Merged
merged 3 commits into from
Aug 20, 2020

Conversation

shubham1172
Copy link
Member

@shubham1172 shubham1172 commented Aug 8, 2020

This PR is based on #10

Splitting '='

Fix by @yuhattor - only split the first instance of '=' instead of all.
Edit: Added another logic to parse values with optional quotes around them.

Original

"key=foobarbaz123=".split('=')
>> Array(3) [ "key", "foobarbaz123", "" ]

Modified

"key=foobarbaz123=".split(/=(?:"(.+)"|(.+))/)
>> Array(3) [ "key", "foobarbaz123=", "" ]

Original

"key=\"foo bar baz 123\"=".split('=')
>> Array(3) [ "key", "\"foo bar baz 123\"", "" ]

Modified

"key=\"foo bar baz 123=\"".split(/=(?:"(.+)"|(.+))/)
>> Array(4) [ "key", "foo bar baz 123=", undefined, "" ]

Splitting whitespace

New fix - do not account for whitespaces that are inside quotes while splitting.

Original

"key1=\"foo bar\" key2=baz".split(' ');
>> Array(3) [ "key1=\"foo", "bar\"", "key2=baz" ]

Modified

"key1=\"foo bar\" key2=baz".match(/(?:[^\s"]+|"[^"]*")+/g) || []
>> Array [ "key1=\"foo bar\"", "key2=baz" ]

yuhattor and others added 2 commits June 16, 2020 12:15
Signed-off-by: Shubham Sharma <shubhamsharma1172@gmail.com>
@shubham1172
Copy link
Member Author

I will be willing to add test cases for the same. I wonder if this can be a good point to set up tests for this repository - provided you have that bandwidth.

@ashishonce
Copy link
Member

Hey Shubham,
although the pattern looks ok.
when I try this rex pattern , I get an extra " , which is unescaped , would mean extra " coming in the value .

am I missing something, or we want to look at this again.
I want to make sure this won't come for any user.

image

image

do you have any working example with new code for this?

Signed-off-by: Shubham Sharma <shubhamsharma1172@gmail.com>
@shubham1172
Copy link
Member Author

Oops @ashishonce, I missed that. Updating the splitting on '=' logic to consider quotes around values.

I have written some tests here, please feel free to checkout https://jsfiddle.net/06yn3zw9/3/

image

Copy link
Member

@ashishonce ashishonce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
we should also think about adding unit test for this .
@narula0781 can we add this to backlog?

@shubham1172
Copy link
Member Author

@ashishonce, I would be happy to volunteer for writing unit tests for this.

@ashishonce
Copy link
Member

@ashishonce, I would be happy to volunteer for writing unit tests for this.

thanks @shubham1172 . let's merge this PR and then you can add a test if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants