You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variables passed to --env with an empty value are incorrectly parsed #3284
When passing env vars to webpack cli using --env, if the value of the variable passed is empty, then the resulting variable name and value is parsed incorrectly. As an example, webpack --env TEST="" results in the following env:
Empty variables passed to --env like --env VAR="" or --env VAR=$NOT_DEFINED result in the env object containing property names like VAR= with the value true.
Empty variables could be represented as one of null, undefined, or "", but certainly should not be true, and the property name should not include the =.
Screenshots
N/A
Please paste the results of npx webpack-cli info here, and mention other relevant information
I'm not invoking Webpack through the terminal, I'm doing it through package.json.
With this script:
"webpack": "webpack --env TEST=\"\""
The result is a property of TEST= with a value of true.
With this:
"webpack": "webpack --env TEST=\\\"\\\""
The result is a property of TEST, but the value is '""' -- which is not an empty string, which would be falsy, but a string containing "", which is truthy.
No matter which variation I try, I can't get a property of TEST with a value that is falsy, which is what I'd expect.
The result is a property of TEST, but the value is '""' -- which is not an empty string, which would be falsy, but a string containing "", which is truthy.
Expected, because you have "" string, it is truthy
But webpack --env TEST="" should be falsy, it is bug on our side
Activity
alexander-akait commentedon Jun 8, 2022
PR welcome
snitin315 commentedon Jun 9, 2022
@benjaminblack @alexander-akait this is a duplicate of #2642 and was fixed in #2643.
We also have test cases for this:
webpack-cli/test/build/config/type/function-with-env/function-with-env.test.js
Lines 120 to 148 in 6075c63
snitin315 commentedon Jun 9, 2022
But yes I feel if it ends with
=we should set it to undefined instead of settingfoo=: true. I'll raise a patch for this.benjaminblack commentedon Jun 9, 2022
I'm not invoking Webpack through the terminal, I'm doing it through package.json.
With this script:
The result is a property of
TEST=with a value oftrue.With this:
The result is a property of
TEST, but the value is'""'-- which is not an empty string, which would be falsy, but a string containing"", which is truthy.No matter which variation I try, I can't get a property of
TESTwith a value that is falsy, which is what I'd expect.alexander-akait commentedon Jun 9, 2022
Expected, because you have
""string, it is truthyBut
webpack --env TEST=""should be falsy, it is bug on our side