Fix tests, reinstate old workaround.
This commit is contained in:
parent
4286a05827
commit
fd8929daae
|
@ -1246,10 +1246,7 @@ if (descriptions.length) {
|
|||
})
|
||||
|
||||
describe.each([
|
||||
[
|
||||
RowExportFormat.CSV,
|
||||
(val: any) => JSON.stringify(val).replace(/"/g, "'"),
|
||||
],
|
||||
[RowExportFormat.CSV, (val: any) => JSON.stringify(val)],
|
||||
[RowExportFormat.JSON, (val: any) => val],
|
||||
])("import validation (%s)", (_, userParser) => {
|
||||
const basicSchema: TableSchema = {
|
||||
|
|
|
@ -270,6 +270,26 @@ function parseJsonExport<T>(value: any) {
|
|||
if (typeof value !== "string") {
|
||||
return value
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(value)
|
||||
|
||||
return parsed as T
|
||||
} catch (e: any) {
|
||||
if (
|
||||
e.message.startsWith("Expected property name or '}' in JSON at position ")
|
||||
) {
|
||||
// In order to store JSON within CSVs what we used to do is replace double
|
||||
// quotes with single quotes. This results in invalid JSON, so the line
|
||||
// below is a workaround to parse it. However, this method of storing JSON
|
||||
// was never valid, and we don't do it anymore. However, people may have
|
||||
// exported data and stored it, hoping to be able to restore it later, so
|
||||
// we leave this in place to support that.
|
||||
const parsed = JSON.parse(value.replace(/'/g, '"'))
|
||||
return parsed as T
|
||||
}
|
||||
|
||||
// It is not valid JSON
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue