fix(editor): Fix mapping with special characters (#5837)

* fix: Fix mapping with special characters

* refactor: rename var

* test: update more unit tests

* test: update mapping test

* test: update mapping test
This commit is contained in:
Mutasem Aldmour
2023-03-30 15:50:47 +02:00
committed by GitHub
parent ddc8f30e6d
commit f8f584c136
7 changed files with 53 additions and 23 deletions

View File

@@ -6,8 +6,11 @@ export function generatePath(root: string, path: Array<string | number>): string
return `${accu}[${part}]`;
}
if (part.includes('-') || part.includes(' ') || part.includes('.')) {
return `${accu}["${part}"]`;
const special = ['-', ' ', '.', "'", '"', '`', '[', ']', '{', '}', '(', ')', ':', ',', '?'];
const hasSpecial = !!special.find((s) => part.includes(s));
if (hasSpecial) {
const escaped = part.replaceAll("'", "\\'");
return `${accu}['${escaped}']`;
}
return `${accu}.${part}`;