Skip to content

Commit c2ff685

Browse files
JaceHensleymcollina
authored andcommitted
Replace "@" with "AT_SYMBOL" (#228)
1 parent eb9b3f7 commit c2ff685

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,14 +1021,14 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema, subKe
10211021
code += nullable ? `json += obj${accessor} === null ? null : $asBoolean(obj${accessor})` : `json += $asBoolean(obj${accessor})`
10221022
break
10231023
case 'object':
1024-
funcName = (name + key + subKey).replace(/[-.\[\] ]/g, '') // eslint-disable-line
1024+
funcName = (name + key + subKey).replace(/[-.\[\] ]/g, '').replace(/[@]/g, 'AT_SYMBOL') // eslint-disable-line
10251025
laterCode = buildObject(schema, laterCode, funcName, externalSchema, fullSchema)
10261026
code += `
10271027
json += ${funcName}(obj${accessor})
10281028
`
10291029
break
10301030
case 'array':
1031-
funcName = '$arr' + (name + key + subKey).replace(/[-.\[\] ]/g, '') // eslint-disable-line
1031+
funcName = '$arr' + (name + key + subKey).replace(/[-.\[\] ]/g, '').replace(/[@]/g, 'AT_SYMBOL') // eslint-disable-line
10321032
laterCode = buildArray(schema, laterCode, funcName, externalSchema, fullSchema)
10331033
code += `
10341034
json += ${funcName}(obj${accessor})

test/array.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ buildTest({
138138
}
139139
}, { args: [{ a: 'test' }, { b: 1 }] })
140140

141+
buildTest({
142+
title: 'array with weird key',
143+
type: 'object',
144+
properties: {
145+
'@data': {
146+
type: 'array',
147+
items: {
148+
type: 'string'
149+
}
150+
}
151+
}
152+
}, {
153+
'@data': ['test']
154+
})
155+
141156
test('invalid items throw', (t) => {
142157
t.plan(1)
143158
const schema = {

test/basic.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ buildTest({
125125
'@version': 1
126126
})
127127

128+
buildTest({
129+
title: 'deep object with weird keys of type object',
130+
type: 'object',
131+
properties: {
132+
'@data': {
133+
type: 'object',
134+
properties: {
135+
id: {
136+
type: 'string'
137+
}
138+
}
139+
}
140+
}
141+
}, {
142+
'@data': {
143+
id: 'string'
144+
}
145+
})
146+
128147
buildTest({
129148
title: 'deep object with spaces in key',
130149
type: 'object',

0 commit comments

Comments
 (0)