From 4055a29aa9025f5e8c051e8e0d9cec0c6c4d2437 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 11 Dec 2018 13:48:28 -0800 Subject: [PATCH] Fix handling of quotes and backslashes in property sheet values --- src/compiler/generate_code/property_table_json.cc | 10 ++++------ src/compiler/prepare_grammar/flatten_grammar.cc | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/compiler/generate_code/property_table_json.cc b/src/compiler/generate_code/property_table_json.cc index f2ca1061..45663f99 100644 --- a/src/compiler/generate_code/property_table_json.cc +++ b/src/compiler/generate_code/property_table_json.cc @@ -63,11 +63,9 @@ class CodeGenerator { for (const auto &pair : property_set) { if (!first) add(","); first = false; - add("\""); - add(pair.first); - add("\":\""); - add(pair.second); - add("\""); + add_string(pair.first); + add(":"); + add_string(pair.second); } add("}"); } @@ -94,7 +92,7 @@ class CodeGenerator { void add_string(const string &s) { add("\""); for (const char c : s) { - if (c == '"') add("\\"); + if (c == '"' || c == '\\') add("\\"); add(c); } add("\""); diff --git a/src/compiler/prepare_grammar/flatten_grammar.cc b/src/compiler/prepare_grammar/flatten_grammar.cc index e13dc4d4..fad02a23 100644 --- a/src/compiler/prepare_grammar/flatten_grammar.cc +++ b/src/compiler/prepare_grammar/flatten_grammar.cc @@ -162,7 +162,7 @@ pair flatten_grammar(const InitialSyntaxGrammar &gr } result.word_token = grammar.word_token; - + return {result, CompileError::none()}; }