-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
fs: don't alter user provided options
object
#7831
Conversation
This is a fix for #7655. @micnic @thealphanerd This can be safely backported, if necessary. |
LGTM with some comments As I see, in some fs stream prototype constructors About tests, it would be good to have such tests for other methods that receive as parameters user defined objects, cc @nodejs/testing |
); | ||
|
||
assert.doesNotThrow(() => | ||
fs.appendFile(1, 'ABCD', Object.freeze({flag: 'w'}), (e) => assert.ifError(e)) |
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.
Please add common.mustCall()
to the callback.
ef7ad0f
to
54db1c6
Compare
@@ -1377,11 +1377,11 @@ fs.appendFileSync = function(path, data, options) { | |||
throwOptionsError(options); | |||
} | |||
|
|||
if (!options.flag) | |||
options = util._extend({ flag: 'a' }, options); | |||
// don't make changes directly on options object |
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.
minor nit... s/don't/Don't
(there are multiple comments in this doc that start with lower case that should be uppercase)
LGTM |
cc @nodejs/collaborators |
LGTM |
|
@thefourtheye Why does this remove |
> Object.create(Object.create({encoding: 'utf8'})).encoding
'utf8'
> util._extend({}, Object.create({encoding: 'utf8'})).encoding
undefined Doesn't it make this semver-major? |
@ChALkeR because the
|
@yorkie, so, this means that it actually broke those tests? |
Yea, we have to change those cases IMO :-( |
Labeling as semver-major due to a breaking change. Note that it also changes existing tests expectations. Feel free to remove the semver-major label if this will be changed so that all the existing tests pass. Could we keep support for those somehow? Btw, this potentially could break some modules out there, so I'm not even sure if landing this in the current state to 7.0 without a deprecation cycle will be fine. Refs: #7912. Note: it's not |
@nodejs/ctc ... any further thoughts on this? |
What is this |
@silverwind We add few properties to |
@thefourtheye Wouldn't something like:
still alter the original |
The status post must be wrong as there was a failure on aix even though the check above show as green. I assume this was not seen earlier as the test did not make it that far.
|
Hmm, see it passed in an earlier CI run so not sure why that would fail unless there could be some conflict with temp directory generation and other tests running in parallel ? Failure on PPC was unrelated as its related to the know test-tic-processor-issues covered in: #8725 |
Stress run on AIX https://ci.nodejs.org/job/node-stress-single-test/986/ |
Seems to fail consistently in stress run, did the test change since the successful CI run ? |
Investigating locally, believe it may be because the test assumes the write will complete before the read starts which is not guaranteed |
Yes believe it is a race condition in the test. This version passes reliably:
|
7be837a
to
1ecce67
Compare
Awesome. Thanks for digging deeper and providing a fix as well, @mhdawson :-) https://ci.nodejs.org/job/node-stress-single-test/989/ is Green. One last CI Run before landing: https://ci.nodejs.org/job/node-test-pull-request/4437/ |
This patch makes a copy of the `options` object before the fs module functions alter it. PR-URL: nodejs#7831 Fixes: nodejs#7655 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Nicu Micleușanu <micnic90@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
1ecce67
to
e378a56
Compare
I had to rebase because of the linter rule upgrade. New CI: https://ci.nodejs.org/job/node-test-pull-request/4440/ |
FreeBSD failures are not related. Landing this now... |
Landed in 7542bdd |
This does not land cleanly on |
@jasnell Oh, do you want me to PR this targeting 7.x? |
No no, sorry i wasn't clear. Both prs landed in v7.x-staging, I was just On Monday, October 10, 2016, Sakthipriyan Vairamani <
|
Backport PRs will be necessary if desired, this appears to depend on #7165 / I don't know how to resolve easily. |
This patch makes a copy of the `options` object before the fs module functions alter it. PR-URL: nodejs/node#7831 Fixes: nodejs/node#7655 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Nicu Micleușanu <micnic90@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
This patch makes a copy of the `options` object before the fs module functions alter it. PR-URL: nodejs/node#7831 Fixes: nodejs/node#7655 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Nicu Micleușanu <micnic90@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
This patch makes a copy of the `options` object before the fs module functions alter it. PR-URL: nodejs/node#7831 Fixes: nodejs/node#7655 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Nicu Micleușanu <micnic90@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
fs
Description of change
This patch makes a copy of the
options
object before altering it.cc @nodejs/fs