-
-
Notifications
You must be signed in to change notification settings - Fork 97
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: support special characters in default expansion #74
Conversation
@@ -35,9 +35,9 @@ | |||
"readmeFilename": "README.md", | |||
"license": "BSD-2-Clause", | |||
"devDependencies": { | |||
"@hapi/lab": "^24.5.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.
Had to upgrade this because the espree used by 14.x didn't support the regex lookbehind.
DEFINED_EXPAND_WITH_DEFAULT_WITH_SPECIAL_CHARACTERS=${MACHINE:-/default/path:with/colon} | ||
UNDEFINED_EXPAND_WITH_DEFAULT_WITH_SPECIAL_CHARACTERS=${UNDEFINED_ENV_KEY:-/default/path:with/colon} | ||
UNDEFINED_EXPAND_WITH_DEFAULT_WITH_SPECIAL_CHARACTERS_NESTED=${UNDEFINED_ENV_KEY:-${UNDEFINED_ENV_KEY_2:-/default/path:with/colon}} |
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 updated the test cases to include a semicolon to ensure everything is working properly with it.
const matches = Array.from(str.matchAll(rgx)) | ||
return matches.length > 0 ? matches.slice(-1)[0].index : -1 | ||
} | ||
|
||
function _interpolate (envValue, environment, config) { |
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.
The function now works as follows:
- Find the right-most group of variables (it can be a single
$VARIABLE
or a nested one (${VARIABLE:-${NESTED:-default}}
); - Expand the inner-most variable;
- Repeat from point 1 until no more variables are found;
Example with { VAR1: "var1", VAR2: "var2", VAR3: undefined }
FOO=${VAR1}something${VAR2:-$VAR3:-default}
FOO=${VAR1}something${VAR2:-default}
FOO=${VAR1}somethingvar2
FOO=var1somethingvar2
Could I get someone to review this please? Anything I can do to help? |
@vantreeseba confirmed the test case had a typo in it. motdotla#39 (comment)
Friendly ping @motdotla |
Hello? |
Any chance to have this PR reviewed? |
Hi? |
Henlo frien? |
This PR fixes #73 by rewriting the whole library to use a simpler approach to the problem.
I think the code should be more readable now, and support more use cases.