eatonphil/pj

i had a problem with this string in javascript "dhdhddh\"jjdjd#

Opened this issue · 0 comments

We have a string with " inside.
i used lexer function in javascript.

i propose that in javascript for function lex_string

i updated this part of code:

if (c === JSON_QUOTE) {
if (i - 1 >= 0 && string[i - 1] === "\") {
json_string += c;
} else {
return [json_string, string.slice(json_string.length + 1)];
}

here the version in javascript

https://github.com/olivierlama/parse-json-js

function lex_string(string) {
let json_string = "";

if (string[0] === JSON_QUOTE) {
string = string.slice(1);
} else {
return ["None", string];
}
let c;
for (const i in string) {
c = string[i];
if (c === JSON_QUOTE) {
if (i - 1 >= 0 && string[i - 1] === "\") {
json_string += c;
} else {
return [json_string, string.slice(json_string.length + 1)];
}
} else {
json_string += c;
}
}
throw "Expected end-of-string quote";
}