Skip to content

Commit 6fa3d30

Browse files
fix: use printf instead of heredoc for YAML-safe markdown generation
1 parent fc09dcf commit 6fa3d30

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

.github/workflows/gen-preview.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,24 +312,21 @@ jobs:
312312
PREV_URL=$(echo "$PREV_VERSIONS" | jq -r --arg key "$KEY" '.[$key].url // empty')
313313
PREV_COUNT=$(echo "$PREV_VERSIONS" | jq -r --arg key "$KEY" '.[$key].count // 0')
314314
315-
# Security: Use unquoted heredoc for direct variable expansion (safer than sed)
315+
# Build markdown using printf (safer than sed, avoids injection)
316316
if [ -n "$PREV_URL" ] && [ "$PREV_URL" != "null" ]; then
317317
NEW_COUNT=$((PREV_COUNT + 1))
318-
cat >> plot_markdown.txt << PLOTEOF
319-
### ${LIBRARY} (${VARIANT}) - UPDATE
320-
321-
| Before | After |
322-
|--------|-------|
323-
| ![Before](${PREV_URL}) | ![After](${NEW_URL}) |
324-
325-
[View version history (${NEW_COUNT} versions)](${HISTORY_URL})
326-
PLOTEOF
318+
{
319+
printf '### %s (%s) - UPDATE\n\n' "$LIBRARY" "$VARIANT"
320+
printf '| Before | After |\n'
321+
printf '|--------|-------|\n'
322+
printf '| ![Before](%s) | ![After](%s) |\n\n' "$PREV_URL" "$NEW_URL"
323+
printf '[View version history (%s versions)](%s)\n' "$NEW_COUNT" "$HISTORY_URL"
324+
} >> plot_markdown.txt
327325
else
328-
cat >> plot_markdown.txt << PLOTEOF
329-
### ${LIBRARY} (${VARIANT}) - NEW
330-
331-
![${LIBRARY} ${VARIANT}](${NEW_URL})
332-
PLOTEOF
326+
{
327+
printf '### %s (%s) - NEW\n\n' "$LIBRARY" "$VARIANT"
328+
printf '![%s %s](%s)\n' "$LIBRARY" "$VARIANT" "$NEW_URL"
329+
} >> plot_markdown.txt
333330
fi
334331
echo "" >> plot_markdown.txt
335332
fi

0 commit comments

Comments
 (0)