Skip to content

Commit 983d8b5

Browse files
authored
Merge pull request #8 from fabrix-app/v1.1
[fix] value null in config
2 parents a59cd84 + 5e67777 commit 983d8b5

7 files changed

+46
-8
lines changed

lib/Configuration.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export class Configuration extends Map<any, any> {
3434
Object.entries(tree).forEach(([k, v]) => {
3535
// if (typeof v === 'object' && v !== null) {
3636
if (
37-
v instanceof Object
37+
v !== null
38+
&& v instanceof Object
3839
&& typeof v !== 'function'
3940
) {
4041
// If value is an array, flatten by index and don't try to flatten further
@@ -163,7 +164,8 @@ export class Configuration extends Map<any, any> {
163164
*/
164165
private _flattenSet(key, value) {
165166
if (
166-
value instanceof Object
167+
value !== null
168+
&& value instanceof Object
167169
&& typeof value !== 'function'
168170
&& !Array.isArray(value)
169171
) {
@@ -202,7 +204,10 @@ export class Configuration extends Map<any, any> {
202204
}
203205
// If configAction is set to merge, it will default values over the initial config
204206
else if (hasKey && configAction === 'merge') {
205-
if (Array.isArray(value)) {
207+
if (value === null) {
208+
// Do Nothing
209+
}
210+
else if (Array.isArray(value)) {
206211
// Do Nothing
207212
}
208213
else if (typeof value === 'number') {

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fabrix/fabrix",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Strongly Typed Modern Web Application Framework for Node.js",
55
"keywords": [
66
"framework",

test/integration/fabrixapp.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ describe('Fabrix', () => {
159159
})
160160
})
161161

162+
it('should be able to reassign a previously null value', () => {
163+
const def = {
164+
pkg: { },
165+
api: { },
166+
config: {
167+
main: {
168+
spools: [ Testspool ]
169+
},
170+
test: {
171+
prefix: '/api'
172+
}
173+
}
174+
}
175+
const app = new FabrixApp(def)
176+
assert.equal(app.config.get('test.prefix'), '/api')
177+
})
178+
162179
it('should disallow re-assignment of config object', () => {
163180
const def = {
164181
pkg: { },

test/integration/testapp.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = {
77
},
88
config: {
99
test: {
10-
val: 1
10+
val: 1,
11+
prefix: '/api'
1112
},
1213
main: {
1314
paths: {

test/integration/testspool.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = class Testspool extends Spool {
1111
test: {
1212
val: 0,
1313
array: [3, 4, 5],
14-
otherval: 1
14+
otherval: 1,
15+
prefix: null
1516
}
1617
},
1718
api: {

test/lib/Configuration.test.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ describe('lib.Configuration', () => {
7272
array: [1, 2, 3],
7373
subobj: {
7474
attr: 'a'
75-
}
75+
},
76+
nullValue: null
7677
}
7778
}
7879
})
@@ -245,6 +246,19 @@ describe('lib.Configuration', () => {
245246
beforeEach(() => {
246247
config = new lib.Configuration(_.cloneDeep(testConfig))
247248
})
249+
it('should set leaves as well as root', () => {
250+
251+
config.set('test', null)
252+
assert.equal(config.get('test'), null)
253+
config.set('test', 'word')
254+
assert.equal(config.get('test'), 'word')
255+
})
256+
257+
it('should set leaves as well as root on a previously null value', () => {
258+
config.set('customerObject.nullValue', 'word')
259+
assert.equal(config.get('customerObject.nullValue'), 'word')
260+
})
261+
248262
it('should set leaves as well as root', () => {
249263

250264
config.set('test', {test2: {test3: 4}})

0 commit comments

Comments
 (0)