Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upchild_process: ignore undef/proto values of env #15089
Conversation
nodejs-github-bot
added
the
child_process
label
Aug 30, 2017
benjamingr
reviewed
Aug 30, 2017
| @@ -467,7 +467,10 @@ function normalizeSpawnArguments(file, args, options) { | |||
| var envPairs = []; | |||
|
|
|||
| for (var key in env) { | |||
This comment has been minimized.
This comment has been minimized.
benjamingr
Aug 30, 2017
•
Member
I think this should optimally be:
const envPairs = Object.keys(env).filter(Boolean).map(key => `${key}=${env[key]}`)or something similar (ignore empty keys in addition to undefined ones.
I do think it's underspecified though. So I'll wait for someone who understands it better to weigh in.
This comment has been minimized.
This comment has been minimized.
refack
Aug 30, 2017
Member
OMG .filter(Boolean)
I used to do .filter((x) => x), but have alway looked for a built-in.
P.S. @Gerhut in TF&I (node 8.3.0 and newer) for ... of loop are almost 10 time faster than for ... in loops, and it's supports Object.entries()
This comment has been minimized.
This comment has been minimized.
benjamingr
Aug 30, 2017
Member
@refack but the call to Object.keys is itself about as slow as doing for... in - in this particular case I don't think performance is important given the time it takes to create a process and all
This comment has been minimized.
This comment has been minimized.
refack
Aug 30, 2017
Member
@benjamingr agreed.
I'm just promoting TF&I good behaviour (no more CranksharfScript)
This comment has been minimized.
This comment has been minimized.
Gerhut
Aug 30, 2017
Author
Contributor
Since the code around still in legacy Syntax, should I be allowed to use modern syntax? If so I will modify them in modern syntax.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Gerhut
Aug 31, 2017
Author
Contributor
However, for..in includes keys in prototype, and keys-in-prototype of env test exists at https://github.com/nodejs/node/blob/master/test/parallel/test-child-process-env.js#L31-L33 . Changing to Object.keys/entries will fail them
This comment has been minimized.
This comment has been minimized.
BridgeAR
Aug 31, 2017
Member
I think it would be good to remove that test case and only use Object.keys. There is not much reasoning in the original commit about why it was added but I think this is actually a faulty behavior.
This comment has been minimized.
This comment has been minimized.
BridgeAR
Aug 31, 2017
Member
Using filter(Boolean) would be a bad decision to use though as it would remove a empty string and any other falsy value as well.
This comment has been minimized.
This comment has been minimized.
|
Tagging as semver-major preemptively since this is a user facing behavioral change in an API marked I don't feel strongly about it - I just don't want it to be missed. |
benjamingr
added
the
semver-major
label
Aug 30, 2017
This comment has been minimized.
This comment has been minimized.
|
@Gerhut thank you for the contribution. Just to explain the process at this point:
If at any point you would like assistance with the pull request or have any question about the process feel free to ask here. Welcome. |
cjihrig
reviewed
Aug 30, 2017
|
Can you add documentation notes and function level changelog entries for this. |
This comment has been minimized.
This comment has been minimized.
|
LGTM as semver-major |
This comment has been minimized.
This comment has been minimized.
|
I personally am not convinced about this. Why should |
Gerhut
force-pushed the
Gerhut:master
branch
from
fa5df44
to
ea03fc8
Aug 31, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm kind of half-way where @BridgeAR is. I would say |
This comment has been minimized.
This comment has been minimized.
|
I think it makes sense to ignore |
This comment has been minimized.
This comment has been minimized.
|
100 % totally official twitter poll: https://twitter.com/addaleax/status/903796395865452544 |
This comment has been minimized.
This comment has been minimized.
|
Looks like the poll says I personally still think we should not remove it but throw an error instead and the poll did not cover that part but it seems like most people agree on removing it, so I will not hold this off. |
This comment has been minimized.
This comment has been minimized.
|
BTW: need to think about how to make this consistent with assignment (maybe in a future PR) Lines 827 to 842 in 98d8db3 |
Gerhut
force-pushed the
Gerhut:master
branch
from
ea03fc8
to
8c10ccd
Sep 4, 2017
This comment has been minimized.
This comment has been minimized.
|
PR Updated. Moreover, Would "ignore keys in prototype of I just feel this change should be in another PR to discuss separately. There could be an use case that using |
BridgeAR
reviewed
Sep 11, 2017
|
In general LGTM but I would like my comment to be addressed. |
| @@ -466,8 +466,10 @@ function normalizeSpawnArguments(file, args, options) { | |||
| var env = options.env || process.env; | |||
| var envPairs = []; | |||
|
|
|||
| for (var key in env) { | |||
| envPairs.push(key + '=' + env[key]); | |||
| for (const [key, value] of Object.entries(env)) { | |||
This comment has been minimized.
This comment has been minimized.
BridgeAR
Sep 11, 2017
Member
I am not sure how fast Object.entries is and I somewhat expect it to be slower than e.g. using Object.keys or using for ... in with a Object.hasOwnProperty.call(env, key) check. The latter will definitely be faster in upcoming v8 versions but probably not right now.
This comment has been minimized.
This comment has been minimized.
|
@Gerhut I think it is fine to keep it in this PR but it would be just as fine to move it to another one! If this is kept in the PR the commit message has to be updated though. This has to be done one way or the other anyway though since it currently has information that is not necessary for landing. So I think it is your call. If you want to land another commit - feel free to open a second PR for that. |
This comment has been minimized.
This comment has been minimized.
|
I'm -0. |
Gerhut
force-pushed the
Gerhut:master
branch
from
8c10ccd
to
d3e7468
Sep 12, 2017
Gerhut
changed the title
child_process: ignore null/undefined values of env
child_process: ignore undef/proto values of env
Sep 12, 2017
jasnell
approved these changes
Sep 15, 2017
Gerhut
force-pushed the
Gerhut:master
branch
from
d3e7468
to
c3be4f7
Sep 18, 2017
BridgeAR
dismissed
their
stale review
Sep 19, 2017
Dimissed my ok as I am also -0 on the change but I do not want to block it either.
This comment has been minimized.
This comment has been minimized.
|
This is semver major and needs some LGs @nodejs/tsc It is still a tiny bit controversial in general though, so please read all the comments as well. |
This comment has been minimized.
This comment has been minimized.
|
I'm on the fence on this one. Deviating from how null and undefined are handled in |
This comment has been minimized.
This comment has been minimized.
|
I would be in favour of the same change for process.env |
refack
reviewed
Sep 25, 2017
| 'HELLO': 'WORLD' | ||
| 'HELLO': 'WORLD', | ||
| 'UNDEFINED': undefined, | ||
| 'NULL': null |
This comment has been minimized.
This comment has been minimized.
refack
reviewed
Sep 25, 2017
| @@ -412,7 +412,8 @@ Use `cwd` to specify the working directory from which the process is spawned. | |||
| If not given, the default is to inherit the current working directory. | |||
|
|
|||
| Use `env` to specify environment variables that will be visible to the new | |||
| process, the default is [`process.env`][]. | |||
| process, the default is [`process.env`][], `undefined` values in `env` will be | |||
This comment has been minimized.
This comment has been minimized.
refack
Sep 25, 2017
Member
Suggestion keep the old line, and add a new sentence:
process, the default is [`process.env`][].
`undefined` values in `env` will be ignored.
Gerhut
force-pushed the
Gerhut:master
branch
from
c3be4f7
to
cccd9d8
Sep 27, 2017
BridgeAR
requested a review
from nodejs/tsc
Dec 6, 2017
addaleax
approved these changes
Dec 6, 2017
| for (var key in env) { | ||
| envPairs.push(`${key}=${env[key]}`); | ||
| for (const key of Object.keys(env)) { | ||
| const value = env[key] |
This comment has been minimized.
This comment has been minimized.
Gerhut
force-pushed the
Gerhut:master
branch
from
e566e1b
to
5e37647
Dec 6, 2017
This comment has been minimized.
This comment has been minimized.
|
Sorry for only ran |
MylesBorins
force-pushed the
nodejs:master
branch
from
b7405ab
to
7f086dd
Dec 8, 2017
rvagg
referenced this pull request
Dec 19, 2017
Closed
Node.js Foundation Technical Steering Committee (TSC) Meeting 2017-12-20 #447
targos
approved these changes
Jan 15, 2018
This comment has been minimized.
This comment has been minimized.
|
CI before landing: https://ci.nodejs.org/job/node-test-pull-request/12531/ |
This comment has been minimized.
This comment has been minimized.
|
Pushed a fix for Windows. |
This comment has been minimized.
This comment has been minimized.
|
Thanks |
targos
added a commit
to targos/node
that referenced
this pull request
Jan 15, 2018
This comment has been minimized.
This comment has been minimized.
targos
closed this
Jan 15, 2018
targos
added a commit
to targos/node
that referenced
this pull request
Jan 15, 2018
targos
added a commit
to targos/node
that referenced
this pull request
Jan 15, 2018
targos
added a commit
to targos/node
that referenced
this pull request
Jan 15, 2018
targos
referenced this pull request
Jan 15, 2018
Closed
src: delete process.env values set to undefined #18158
targos
added a commit
to targos/node
that referenced
this pull request
Jan 15, 2018
Trott
removed
the
tsc-review
label
Jan 16, 2018
This comment has been minimized.
This comment has been minimized.
|
In future please run CITGM before landing semver major commits edit: for context this broke CITGM |
This comment has been minimized.
This comment has been minimized.
|
Sorry about that |
This comment has been minimized.
This comment has been minimized.
|
I'll just leave a note here to anyone landing this in the future, it can't land without #18210. |
Gerhut commentedAug 30, 2017
•
edited
At present, undefined values of env option will be transferred as an "undefined" string value and values in the prototype will also be included, which are not usual behaviors.
Since non-string env values & prototype values are undocumented, this change may be treated as a bugfix or a breaking change.
Tested on Mac, Windows not yet.
Fixes: #15087
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
child_process