Permalink
Browse files

Handle octals as numbers, not strings

  • Loading branch information...
1 parent 929b93d commit 83c2004a18a7ab47544381d3aabca94331c6b198 @isaacs isaacs committed Aug 30, 2012
Showing with 9 additions and 6 deletions.
  1. +4 −2 config-defs.js
  2. +3 −3 npmconf.js
  3. +2 −1 test/basic.js
View
6 config-defs.js
@@ -23,11 +23,13 @@ function Octal () {}
function validateOctal (data, k, val) {
// must be either an integer or an octal string.
if (typeof val === "number") {
- data[k] = "0" + val.toString(8)
+ data[k] = val
+ return true
}
+
if (typeof val === "string") {
if (val.charAt(0) !== "0" || isNaN(val)) return false
- data[k] = "0" + parseInt(val, 8).toString(8)
+ data[k] = parseInt(val, 8).toString(8)
}
}
View
6 npmconf.js
@@ -281,8 +281,8 @@ function parseField (f, k, emptyIsFalse) {
var isPath = -1 !== typeList.indexOf(path)
var isBool = -1 !== typeList.indexOf(Boolean)
var isString = -1 !== typeList.indexOf(String)
- var isNumber = -1 !== typeList.indexOf(Number) ||
- -1 !== typeList.indexOf(Octal)
+ var isOctal = -1 !== typeList.indexOf(Octal)
+ var isNumber = isOctal || (-1 !== typeList.indexOf(Number))
f = (''+f).trim()
@@ -310,7 +310,7 @@ function parseField (f, k, emptyIsFalse) {
}
if (isNumber && !isNaN(f))
- f = +f
+ f = isOctal ? parseInt(f, 8) : +f
return f
}
View
3 test/basic.js
@@ -34,7 +34,7 @@ var gcData = { 'package-config:foo': 'boo' }
var biData = {}
-var cli = { foo: 'bar' }
+var cli = { foo: 'bar', umask: 022 }
var expectList =
[ cli,
@@ -67,6 +67,7 @@ test('no builtin', function (t) {
t.same(npmconf.rootConf.list, [])
t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
t.equal(conf.root, npmconf.defs.defaults)
+ t.equal(conf.get('umask'), 022)
t.end()
})
})

0 comments on commit 83c2004

Please sign in to comment.