fix(parse): don't bail out on encountering weird characters

replace all \x3C(<) with its valid unique escape sequence
This commit is contained in:
zyachel 2024-04-08 00:22:51 +05:30
parent 1073e61530
commit f11d3f2ac6
3 changed files with 18 additions and 8 deletions

11
utils/parse.js Normal file
View file

@ -0,0 +1,11 @@
const invalidLessThan = /\\x3C/g;
const validLessThan = '\\u003C';
/**
* parses and corrects invalid escape sequences
* @param {string} data
* @returns {Record<PropertyKey, any>}
*/
const parse = data => JSON.parse(data.replace(invalidLessThan, validLessThan));
export default parse;