Skip to content

Commit fbd3ace

Browse files
committed
fix(isc): codemod note escaping + comment stripping + array field parsing
Codemod fixes: - Strip YAML inline comments from note text - Unescape YAML escapes before re-escaping for ISC - Prevents double-escaping of quotes in notes DocumentBuilder fix: - parse_array_field splits field_block content into array items - URL and other array fields properly parsed from brace blocks Result: 259/289 deep equivalent (up from 247)
1 parent b079f70 commit fbd3ace

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

lib/interscript/isc/codemod.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,14 @@ def emit_heredoc_note(indent)
417417
def emit_note_with_continuation(note_indent)
418418
@out << "\n#{note_indent}note \""
419419
text = @scanner.scan(/[^\n]+/).to_s
420-
@out << text.gsub('"', '\\"')
420+
# Strip YAML inline comments: "text # comment" → "text"
421+
text = text.sub(/\s+#.*$/, "")
422+
# Strip outer quotes if the YAML list item was quoted: - "text"
423+
text = text[1..-2] if text.start_with?('"') && text.end_with?('"')
424+
text = text[1..-2] if text.start_with?("'") && text.end_with?("'")
425+
# Unescape YAML escape sequences, then re-escape for ISC
426+
text = text.gsub('\\"', '"').gsub("\\\\", "\\")
427+
@out << text.gsub('\\', '\\\\\\\\').gsub('"', '\\"')
421428
# Consume continuation lines: any subsequent line indented deeper
422429
# than the `- ` marker is part of the same note. Blank lines between
423430
# continuations are preserved as \n.

lib/interscript/isc/document_builder.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ def unescape_braces(text)
7777
text.gsub(/\\([{}\\])/, '\1')
7878
end
7979

80+
def parse_array_field(val)
81+
return [] if val.nil? || val.to_s.strip.empty?
82+
# If the value contains newlines or `- ` markers, split into items
83+
items = val.to_s.split(/\n+/)
84+
.map { |l| l.strip.sub(/\A-\s*/, "") }
85+
.reject(&:empty?)
86+
return [val.to_s.strip] if items.empty?
87+
items
88+
end
89+
8090
def normalize_heredoc(text)
8191
lines = text.lines.map(&:chomp)
8292
content_lines = lines.reject { |l| l.strip.empty? }
@@ -155,7 +165,7 @@ def extract_metadata(arr)
155165
end
156166
# DSL stores these as Arrays — match that convention.
157167
if ARRAY_METADATA_FIELDS.include?(name)
158-
h[name] = val.to_s.empty? ? [] : [val]
168+
h[name] = parse_array_field(val)
159169
else
160170
h[name] = val
161171
end

0 commit comments

Comments
 (0)