Comparing version 5.0.0 to 5.1.0
@@ -41,4 +41,7 @@ /* | ||
var hashPublicSuffixedKeys = []; | ||
Object.keys(obj).forEach(function (key) { | ||
if (key !== '#public') { | ||
if (/.+#public$/.test(key)) { | ||
hashPublicSuffixedKeys.push(key); | ||
} else if (key !== '#public') { | ||
// Have to extract public and non-public keys separately, otherwise we lose information | ||
@@ -53,2 +56,13 @@ var resolvedPublic = resolvePublic(obj[key], false, true); | ||
}); | ||
if (hashPublicSuffixedKeys.length > 0) { | ||
obj['#public'] = obj['#public'] || {}; | ||
hashPublicSuffixedKeys.forEach(function (hashPublicSuffixedKey) { | ||
var keyWithoutSuffix = hashPublicSuffixedKey.replace(/#public$/, ''); | ||
if (keyWithoutSuffix in obj['#public']) { | ||
throw new Error(hashPublicSuffixedKey + ' clashes with ' + keyWithoutSuffix + ' inside #public block'); | ||
} | ||
obj['#public'][keyWithoutSuffix] = obj[hashPublicSuffixedKey]; | ||
delete obj[hashPublicSuffixedKey]; | ||
}); | ||
} | ||
@@ -55,0 +69,0 @@ if (typeof obj['#public'] !== 'undefined') { |
@@ -5,3 +5,3 @@ { | ||
"description": "Configuration", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"repository": { | ||
@@ -51,4 +51,5 @@ "type": "git", | ||
"mocha": "*", | ||
"unexpected": "10.8.1" | ||
"unexpected": "10.8.1", | ||
"unexpected-fs": "2.1.3" | ||
} | ||
} |
/*global describe, it, before*/ | ||
var expect = require('unexpected'); | ||
var expect = require('unexpected').clone().use(require('unexpected-fs')); | ||
var oconf = require('../../lib/index'); | ||
@@ -390,2 +390,54 @@ | ||
}); | ||
expect.addAssertion('<object> to resolve to <object>', function (expect, subject, value) { | ||
return expect(function () { | ||
expect(oconf.load('/testdata/config.cjson'), 'to equal', value); | ||
}, 'with fs mocked out', { | ||
'/testdata': { | ||
'config.cjson': JSON.stringify(subject) | ||
} | ||
}, 'not to error'); | ||
}); | ||
expect.addAssertion('<object> to result in error <any?>', function (expect, subject, value) { | ||
return expect(function () { | ||
expect(oconf.load('/testdata/config.cjson'), 'to equal', value); | ||
}, 'with fs mocked out', { | ||
'/testdata': { | ||
'config.cjson': JSON.stringify(subject) | ||
} | ||
}, 'to error', value); | ||
}); | ||
describe('with a #public-suffixed key', function () { | ||
it('treats the key as if contained inside a #public block', function () { | ||
expect({ | ||
foo: { | ||
'bar#public': 123, | ||
quux: 456 | ||
} | ||
}, 'to resolve to', { | ||
foo: { | ||
bar: 123, | ||
quux: 456 | ||
}, | ||
'#public': { | ||
foo: { | ||
bar: 123 | ||
} | ||
} | ||
}); | ||
}); | ||
it('complains if a #public-suffixed key shadows an entry inside a #public block', function () { | ||
expect({ | ||
foo: { | ||
'#public': { | ||
foo: 123 | ||
}, | ||
'foo#public': 456 | ||
} | ||
}, 'to result in error', new Error('foo#public clashes with foo inside #public block')); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
65638
1025
3
7