Skip to content

Commit e660c55

Browse files
committed
Merge pull request #159 from sparkprime/text_block_escaping
Fix bug where escaping was still performed in text blocks
2 parents 4871195 + 2bdad69 commit e660c55

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

core/desugarer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,9 @@ class Desugarer {
582582
// Nothing to do.
583583

584584
} else if (auto *ast = dynamic_cast<LiteralString*>(ast_)) {
585-
ast->value = jsonnet_string_unescape(ast->location, ast->value);
585+
if (ast->tokenKind != LiteralString::BLOCK) {
586+
ast->value = jsonnet_string_unescape(ast->location, ast->value);
587+
}
586588
ast->tokenKind = LiteralString::DOUBLE;
587589
ast->blockIndent.clear();
588590

test_suite/text_block.jsonnet

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ local str1 = |||
6666
std.assertEqual(str1, "text\n") &&
6767
6868
69+
// Escape chars
70+
local str1 = |||
71+
\n
72+
|||;
73+
74+
std.assertEqual(str1, "\\n\n") &&
75+
76+
6977
// Blank line with trailing whitespace
7078
local blank_line1 = |||
7179
foo

test_suite/text_block.jsonnet.fmt.golden

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ local str1 = |||
6666
std.assertEqual(str1, "text\n") &&
6767

6868

69+
// Escape chars
70+
local str1 = |||
71+
\n
72+
|||;
73+
74+
std.assertEqual(str1, "\\n\n") &&
75+
76+
6977
// Blank line with trailing whitespace
7078
local blank_line1 = |||
7179
foo

0 commit comments

Comments
 (0)