Fixing issue with single quotes in strings breaking JSON parsing.
This commit is contained in:
parent
5f4199a3fb
commit
b4d91769cc
|
@ -25,6 +25,8 @@ export function generateRowIdField(keyProps: any[] = []) {
|
||||||
keyProps = [keyProps]
|
keyProps = [keyProps]
|
||||||
}
|
}
|
||||||
// this conserves order and types
|
// this conserves order and types
|
||||||
|
// we have to swap the double quotes to single quotes for use in HBS statements
|
||||||
|
// when using the literal helper the double quotes can break things
|
||||||
return encodeURIComponent(JSON.stringify(keyProps).replace(/"/g, "'"))
|
return encodeURIComponent(JSON.stringify(keyProps).replace(/"/g, "'"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +35,11 @@ export function breakRowIdField(_id: string) {
|
||||||
if (!_id) {
|
if (!_id) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return JSON.parse(decodeURIComponent(_id))
|
// have to replace on the way back as we swapped out the double quotes
|
||||||
|
// when encoding, but JSON can't handle the single quotes
|
||||||
|
const decoded = decodeURIComponent(_id).replace(/'/g, "\"")
|
||||||
|
const parsed = JSON.parse(decoded)
|
||||||
|
return Array.isArray(parsed) ? parsed : [parsed]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertType(type: string, map: { [key: string]: any }) {
|
export function convertType(type: string, map: { [key: string]: any }) {
|
||||||
|
|
Loading…
Reference in New Issue