From aa5311d1bfb4cc95a2f7dc48fd777d220ef7023f Mon Sep 17 00:00:00 2001 From: Dmitry Antonov Date: Tue, 30 Nov 2021 21:33:26 +0300 Subject: [PATCH 1/2] Fix backslash before closing quote parsing issue Fixes edge case with value ending with a backslash, even escaped: ``` "UserLocalConfigStore" { "friends" { "9734658" "Grocel" "5318652" "/Hexalitos\\" <-- this one "19358028" "put in" } } ``` ``` SyntaxError: VDF.parse: invalid syntax on line 8: " ``` As an additional bonus, adds strict comparison in this line where it's appropriate --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index be788b8..a2218cb 100644 --- a/main.js +++ b/main.js @@ -71,7 +71,7 @@ function parse(text, options) { var comment_slash_pos = -1; sanitization: for (var l = 0; l < _line.length; l++) { switch (_line.charAt(l)) { - case '"': if (_line.charAt(l-1) != '\\') odd = !odd; break; + case '"': if (_line.charAt(l - 1) !== '\\' || _line.charAt(l - 2) === '\\') odd = !odd; break; case '/': if (!odd) { comment_slash_pos = l; break sanitization; } break; case '{': if (!odd) { _line = _line.slice(0, l) + "\n{\n" + _line.slice(l+1); l+=2; } break; case '}': if (!odd) { _line = _line.slice(0, l) + "\n}\n" + _line.slice(l+1); l+=2; } break; From bd43251ff9e402f57d8e7f84af5a20a4d933fa66 Mon Sep 17 00:00:00 2001 From: Dmitry Antonov Date: Tue, 30 Nov 2021 21:34:50 +0300 Subject: [PATCH 2/2] Restore original operator formatting --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index a2218cb..de39de7 100644 --- a/main.js +++ b/main.js @@ -71,7 +71,7 @@ function parse(text, options) { var comment_slash_pos = -1; sanitization: for (var l = 0; l < _line.length; l++) { switch (_line.charAt(l)) { - case '"': if (_line.charAt(l - 1) !== '\\' || _line.charAt(l - 2) === '\\') odd = !odd; break; + case '"': if (_line.charAt(l-1) !== '\\' || _line.charAt(l-2) === '\\') odd = !odd; break; case '/': if (!odd) { comment_slash_pos = l; break sanitization; } break; case '{': if (!odd) { _line = _line.slice(0, l) + "\n{\n" + _line.slice(l+1); l+=2; } break; case '}': if (!odd) { _line = _line.slice(0, l) + "\n}\n" + _line.slice(l+1); l+=2; } break;