Skip to content

Commit fb4baab

Browse files
authored
Merge pull request #57 from SerayaEryn/fix-error-if-spaces-in-key
Fix error being thrown because of spaces in key
2 parents cce2fd1 + 7644fb0 commit fb4baab

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,14 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema, subKe
532532
`
533533
break
534534
case 'object':
535-
funcName = (name + key + subKey).replace(/[-.\[\]]/g, '') // eslint-disable-line
535+
funcName = (name + key + subKey).replace(/[-.\[\] ]/g, '') // eslint-disable-line
536536
laterCode = buildObject(schema, laterCode, funcName, externalSchema, fullSchema)
537537
code += `
538538
json += ${funcName}(obj${accessor})
539539
`
540540
break
541541
case 'array':
542-
funcName = (name + key + subKey).replace(/[-.\[\]]/g, '') // eslint-disable-line
542+
funcName = (name + key + subKey).replace(/[-.\[\] ]/g, '') // eslint-disable-line
543543
laterCode = buildArray(schema, laterCode, funcName, externalSchema, fullSchema)
544544
code += `
545545
json += ${funcName}(obj${accessor})

test/basic.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ buildTest({
129129
'@version': 1
130130
})
131131

132+
buildTest({
133+
'title': 'deep object with spaces in key',
134+
'type': 'object',
135+
'properties': {
136+
'spaces in key': {
137+
'type': 'object',
138+
'properties': {
139+
'something': {
140+
'type': 'integer'
141+
}
142+
}
143+
}
144+
}
145+
}, {
146+
'spaces in key': {
147+
'something': 1
148+
}
149+
})
150+
132151
buildTest({
133152
'title': 'with null',
134153
'type': 'object',

0 commit comments

Comments
 (0)