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

fix: support special characters in default expansion #74

Merged
merged 4 commits into from Dec 16, 2022

Conversation

FezVrasta
Copy link
Contributor

@FezVrasta FezVrasta commented Mar 29, 2022

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.

@@ -35,9 +35,9 @@
"readmeFilename": "README.md",
"license": "BSD-2-Clause",
"devDependencies": {
"@hapi/lab": "^24.5.1",
Copy link
Contributor Author

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.

Comment on lines +14 to +16
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}}
Copy link
Contributor Author

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) {
Copy link
Contributor Author

@FezVrasta FezVrasta Mar 30, 2022

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:

  1. Find the right-most group of variables (it can be a single $VARIABLE or a nested one (${VARIABLE:-${NESTED:-default}});
  2. Expand the inner-most variable;
  3. Repeat from point 1 until no more variables are found;

Example with { VAR1: "var1", VAR2: "var2", VAR3: undefined }

  1. FOO=${VAR1}something${VAR2:-$VAR3:-default}
  2. FOO=${VAR1}something${VAR2:-default}
  3. FOO=${VAR1}somethingvar2
  4. FOO=var1somethingvar2

tests/.env Outdated Show resolved Hide resolved
@FezVrasta
Copy link
Contributor Author

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)
@FezVrasta
Copy link
Contributor Author

Friendly ping @motdotla

@FezVrasta
Copy link
Contributor Author

Hello?

@FezVrasta
Copy link
Contributor Author

Any chance to have this PR reviewed?

@FezVrasta
Copy link
Contributor Author

Hi?

@FezVrasta
Copy link
Contributor Author

FezVrasta commented Dec 16, 2022

Henlo frien?

@motdotla motdotla merged commit b38930f into motdotla:master Dec 16, 2022
fbnfgc added a commit to fbnfgc/serverless that referenced this pull request Mar 14, 2023
medikoo pushed a commit to serverless/serverless that referenced this pull request Mar 15, 2023
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.

default value not working if value includes colon (or other special chars)
2 participants