Skip to content

fix: support special characters in default expansion#74

Merged
motdotla merged 4 commits intomotdotla:masterfrom
FezVrasta:master
Dec 16, 2022
Merged

fix: support special characters in default expansion#74
motdotla merged 4 commits intomotdotla:masterfrom
FezVrasta:master

Conversation

@FezVrasta
Copy link
Copy Markdown
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.

Comment thread package.json
"readmeFilename": "README.md",
"license": "BSD-2-Clause",
"devDependencies": {
"@hapi/lab": "^24.5.1",
Copy link
Copy Markdown
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 thread tests/.env
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
Copy Markdown
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.

Comment thread lib/main.js
return matches.length > 0 ? matches.slice(-1)[0].index : -1
}

function _interpolate (envValue, environment, config) {
Copy link
Copy Markdown
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

Comment thread tests/.env Outdated
@FezVrasta
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Friendly ping @motdotla

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Hello?

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Any chance to have this PR reviewed?

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Hi?

@FezVrasta
Copy link
Copy Markdown
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