diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index a2c78677..3c5f93da 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -288,7 +288,7 @@ def format(q) q.text(value) else q.text(q.quote) - q.text(value[1] == "\"" ? "\\\"" : value[1]) + q.text(value[1] == q.quote ? "\\#{q.quote}" : value[1]) q.text(q.quote) end end diff --git a/test/plugin/single_quotes_test.rb b/test/plugin/single_quotes_test.rb index 6ce10448..b1359ac7 100644 --- a/test/plugin/single_quotes_test.rb +++ b/test/plugin/single_quotes_test.rb @@ -8,6 +8,14 @@ def test_empty_string_literal assert_format("''\n", "\"\"") end + def test_character_literal_with_double_quote + assert_format("'\"'\n", "?\"") + end + + def test_character_literal_with_singlee_quote + assert_format("'\\''\n", "?'") + end + def test_string_literal assert_format("'string'\n", "\"string\"") end