Skip to content

Commit f78a974

Browse files
committed
fix(codemod): correctly escape literal \u sequences in note text
The .imp files contain literal ’ text (6 chars). The ISC parser interprets \uXXXX as unicode escapes in quoted strings, producing the actual character instead of literal text. Fix: escape \u as \\u in the ISC source so the parser produces literal \u (matching the DSL). The gsub replacement needs 8 backslashes in Ruby source to produce 2 backslashes in output. Result: 278/289 deep equivalent
1 parent 68e5592 commit f78a974

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/interscript/isc/codemod.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def emit_note_with_continuation(note_indent)
437437
text = text[1..] if text.start_with?("'") && !text.end_with?("'")
438438
# Unescape YAML escape sequences, then re-escape for ISC
439439
text = text.gsub('\\"', '"').gsub("\\\\", "\\")
440-
@out << text.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\u")
440+
@out << text.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
441441
# Consume continuation lines: any subsequent line indented deeper
442442
# than the `- ` marker is part of the same note. Blank lines between
443443
# continuations are preserved as \n.
@@ -447,13 +447,13 @@ def emit_note_with_continuation(note_indent)
447447
@scanner.scan(/\n([ \t]+)/)
448448
@out << "\\n" + @scanner[1].strip + " "
449449
cont = @scanner.scan(/[^\n]+/).to_s
450-
@out << cont.gsub('"', '\\"')
450+
@out << cont.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
451451
elsif @scanner.check(/\n[ \t]*\n[ \t]{#{note_indent.length + 1},}\S/)
452452
# Blank line then indented continuation
453453
@scanner.scan(/\n[ \t]*\n([ \t]+)/)
454454
@out << "\\n" + @scanner[1].strip + " "
455455
cont = @scanner.scan(/[^\n]+/).to_s
456-
@out << cont.gsub('"', '\\"')
456+
@out << cont.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
457457
else
458458
break
459459
end
@@ -488,11 +488,13 @@ def read_heredoc_into_string(indent)
488488
@out << "\\n\\n"
489489
elsif @scanner.scan(/\n([ \t]+[^\n]*)/)
490490
# Indented line — preserve raw content (indent + text)
491-
@out << "\\n" + @scanner[1].to_s.gsub('"', '\\"')
491+
line = @scanner[1].to_s.gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
492+
@out << "\\n" + line
492493
elsif @scanner.scan(/\n/)
493494
@out << "\\n"
494495
elsif @scanner.scan(/([^\n]+)/)
495-
@out << @scanner[1].gsub('"', '\\"')
496+
line = @scanner[1].gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
497+
@out << line
496498
else
497499
return
498500
end

0 commit comments

Comments
 (0)