Skip to content

Commit f028720

Browse files
committed
fix(isc): strip trailing quote leaked from multi-line YAML notes
YAML quoted list items spanning multiple lines have opening " on first line and closing " on last line. The closing " was leaking into the extracted note value. Result: 270/289 deep equivalent
1 parent 8cc4302 commit f028720

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/interscript/isc/codemod.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ def emit_note_with_continuation(note_indent)
423423
# Strip outer quotes if the YAML list item was quoted: - "text"
424424
text = text[1..-2] if text.start_with?('"') && text.end_with?('"')
425425
text = text[1..-2] if text.start_with?("'") && text.end_with?("'")
426+
# Also strip leading quote when text spans multiple lines (closing on later line)
427+
text = text[1..] if text.start_with?('"') && !text.end_with?('"')
426428
text = text[1..] if text.start_with?("'") && !text.end_with?("'")
427429
# Unescape YAML escape sequences, then re-escape for ISC
428430
text = text.gsub('\\"', '"').gsub("\\\\", "\\")

lib/interscript/isc/document_builder.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,16 @@ def parse_array_field(val)
8181
return [] if val.nil? || val.to_s.strip.empty?
8282
text = val.to_s
8383
return [text.strip] unless text.include?("\n-")
84-
# Multi-line YAML list: merge continuation lines (joined with space)
84+
# Multi-line YAML list: merge continuation lines preserving paragraph breaks
8585
items = []
86-
current = nil
8786
text.lines.each do |l|
8887
stripped = l.strip
8988
if stripped.start_with?("- ")
9089
items << stripped[2..]
90+
elsif stripped.empty? && items.any?
91+
items[-1] = (items[-1] || "") + "\n\n"
9192
elsif !stripped.empty? && items.any?
92-
items[-1] += " " + stripped
93+
items[-1] = (items[-1] || "") + "\n" + stripped
9394
end
9495
end
9596
items.empty? ? [text.strip] : items
@@ -145,11 +146,16 @@ def extract_metadata(arr)
145146
h[:notes] ||= []
146147
Array(field[:notes]).each do |n|
147148
note_val = n.is_a?(Hash) ? n[:note] : n
148-
h[:notes] << normalize_heredoc(unquote(note_val).to_s)
149+
note_text = normalize_heredoc(unquote(note_val).to_s)
150+
note_text = note_text.sub(/"\z/, "")
151+
h[:notes] << note_text
149152
end
150153
when field.key?(:note)
151154
h[:notes] ||= []
152-
h[:notes] << normalize_heredoc(unquote(field[:note]).to_s)
155+
note_text = normalize_heredoc(unquote(field[:note]).to_s)
156+
# Strip trailing " leaked from multi-line YAML quoted items
157+
note_text = note_text.sub(/"\z/, "")
158+
h[:notes] << note_text
153159
when field.key?(:provenance)
154160
h[:provenance] ||= []
155161
h[:provenance] << unquote(field[:provenance])

0 commit comments

Comments
 (0)