-
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
Some possible bugs concerning fs.appendFile() and fs.writeFile() #11595
Comments
Agreed that this is indeed an issue.
shows that 'cb' is used as data, as well as the callback. Looking at the writeFile implementation fs.watchFile I see that the callback and the data being extracted without cohesion between them, as the root case. For example, callback is extracted as the last param, and data is extracted as the second param. No assertion is made to make sure they are discretely different, and mandatory, as the per the API doc: |
@vsemozhetbyt Just curious, how did you find out that |
@seishun I was trying to eliminate deopts in some |
The functions `fs.appendFile()` and `fs.writeFile()` were being called without the required `data` argument. Refs: #11595 PR-URL: #11601 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
The functions `fs.appendFile()` and `fs.writeFile()` were being called without the required `data` argument. Refs: #11595 PR-URL: #11601 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
yeah, fs.writeFile = function(path, data, options, callback) {
callback = maybeCallback(arguments[arguments.length - 1]);
options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'w' });
// ...
} So, in @vsemozhetbyt case, What if we will add a small check here: fs.writeFile = function(path, data, options, callback) {
if (typeof data === 'function') throw new Error('you need to specify data');
callback = maybeCallback(arguments[arguments.length - 1]);
options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'w' });
// ...
} I believe that order What you think? UPD: I like @vsemozhetbyt 's approach with |
@vsemozhetbyt BTW, it can be closed due works as expected, since docs are saying that you need to specify 3 arguments and only |
@ghaiklor Let's have an eccentric method for a change) |
The functions `fs.appendFile()` and `fs.writeFile()` were being called without the required `data` argument. Refs: #11595 Backport-PR-URL: #12477 PR-URL: #11601 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
The functions `fs.appendFile()` and `fs.writeFile()` were being called without the required `data` argument. Refs: #11595 Backport-PR-URL: #12477 PR-URL: #11601 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Fixed in 208db56. |
The functions `fs.appendFile()` and `fs.writeFile()` were being called without the required `data` argument. Refs: nodejs/node#11595 Backport-PR-URL: nodejs/node#12477 PR-URL: nodejs/node#11601 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
1.
fs.appendFile()
andfs.writeFile()
can be called without mandatorydata
parameter, while not throwing any error messages. Thus, the only second parameter serves asdata
andcallback
(mandatory as well) parameters at the same time.This code runs without any errors and produces 2 files with the same content:
It seems this is hardly an expected behavior.
2.
test/parallel/test-fs-null-bytes.js
tests these functions with wrong parameters scheme, i.e. without mandatorydata
parameter. This may be not very important for the test aim, but it makes it somehow compromised.The text was updated successfully, but these errors were encountered: