summaryrefslogtreecommitdiff
path: root/lib/internal/validators.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-10 23:06:33 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-15 17:38:12 +0100
commit1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e (patch)
tree0c43b3ce5635fd76d6c9aabc1a37fe638cbdb0be /lib/internal/validators.js
parent6f77af541e4336037f08a876e1a3fa657fd22675 (diff)
downloadandroid-node-v8-1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e.tar.gz
android-node-v8-1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e.tar.bz2
android-node-v8-1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e.zip
fs: improve mode validation
Do not return a default mode in case invalid mode values are provided. This strictens and simplifies the function by reusing existing functionality. PR-URL: https://github.com/nodejs/node/pull/26575 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Diffstat (limited to 'lib/internal/validators.js')
-rw-r--r--lib/internal/validators.js13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/internal/validators.js b/lib/internal/validators.js
index 0ecf286266..6de46349c0 100644
--- a/lib/internal/validators.js
+++ b/lib/internal/validators.js
@@ -35,24 +35,17 @@ function validateMode(value, name, def) {
}
if (typeof value === 'number') {
- if (!Number.isInteger(value)) {
- throw new ERR_OUT_OF_RANGE(name, 'an integer', value);
- } else {
- // 2 ** 32 === 4294967296
- throw new ERR_OUT_OF_RANGE(name, '>= 0 && < 4294967296', value);
- }
+ validateInt32(value, name, 0, 2 ** 32 - 1);
}
if (typeof value === 'string') {
if (!octalReg.test(value)) {
throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc);
}
- const parsed = parseInt(value, 8);
- return parsed;
+ return parseInt(value, 8);
}
- // TODO(BridgeAR): Only return `def` in case `value == null`
- if (def !== undefined) {
+ if (def !== undefined && value == null) {
return def;
}