Skip to content

Commit b5edb97

Browse files
committed
fix(codemod): strip trailing YAML closing quote from multi-line notes
The codemod now tracks whether a note was YAML-quoted (single or double) and strips the trailing closing delimiter from the last continuation line. This replaces the blunt trailing-quote strip in DocumentBuilder which was removing legitimate trailing quotes. Result: 283/289 deep equivalent (up from 278)
1 parent f78a974 commit b5edb97

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

lib/interscript/isc/codemod.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ def emit_note_with_continuation(note_indent)
429429
text = @scanner.scan(/[^\n]+/).to_s
430430
# Strip YAML inline comments: "text # comment" → "text"
431431
text = text.sub(/\s+#.*$/, "")
432+
# Track if item was YAML-quoted (for trailing quote cleanup)
433+
was_dquote = text.start_with?('"') && !text.end_with?('"')
434+
was_squote = text.start_with?("'") && !text.end_with?("'")
432435
# Strip outer quotes if the YAML list item was quoted: - "text"
433436
text = text[1..-2] if text.start_with?('"') && text.end_with?('"')
434437
text = text[1..-2] if text.start_with?("'") && text.end_with?("'")
@@ -447,17 +450,26 @@ def emit_note_with_continuation(note_indent)
447450
@scanner.scan(/\n([ \t]+)/)
448451
@out << "\\n" + @scanner[1].strip + " "
449452
cont = @scanner.scan(/[^\n]+/).to_s
450-
@out << cont.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
453+
cont = cont.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
454+
@out << cont
451455
elsif @scanner.check(/\n[ \t]*\n[ \t]{#{note_indent.length + 1},}\S/)
452456
# Blank line then indented continuation
453457
@scanner.scan(/\n[ \t]*\n([ \t]+)/)
454458
@out << "\\n" + @scanner[1].strip + " "
455459
cont = @scanner.scan(/[^\n]+/).to_s
456-
@out << cont.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
460+
cont = cont.gsub('\\', '\\\\\\\\').gsub('"', '\\"').gsub("\\u", "\\\\\\\\u")
461+
@out << cont
457462
else
458463
break
459464
end
460465
end
466+
# If item was multi-line YAML-quoted, strip the trailing closing
467+
# quote that leaked from the last continuation line.
468+
if was_dquote && @out.end_with?('\\"')
469+
@out[-2..] = ""
470+
elsif was_squote && @out.end_with?("'")
471+
@out[-1..] = ""
472+
end
461473
@out << "\""
462474
end
463475

lib/interscript/isc/document_builder.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,11 @@ def extract_metadata(arr)
148148
h[:notes] ||= []
149149
Array(field[:notes]).each do |n|
150150
note_val = n.is_a?(Hash) ? n[:note] : n
151-
note_text = normalize_heredoc(unquote(note_val).to_s)
152-
note_text = note_text.sub(/["']\z/, "")
153-
h[:notes] << note_text
151+
h[:notes] << normalize_heredoc(unquote(note_val).to_s)
154152
end
155153
when field.key?(:note)
156154
h[:notes] ||= []
157-
note_text = normalize_heredoc(unquote(field[:note]).to_s)
158-
note_text = note_text.sub(/["']\z/, "")
159-
h[:notes] << note_text
155+
h[:notes] << normalize_heredoc(unquote(field[:note]).to_s)
160156
when field.key?(:provenance)
161157
h[:provenance] ||= []
162158
h[:provenance] << unquote(field[:provenance])

0 commit comments

Comments
 (0)