diff --git a/check.sh b/check.sh index ee756fe..79a2199 100755 --- a/check.sh +++ b/check.sh @@ -23,12 +23,14 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk ' if (fence_char == "`" || fence_char == "~") { while (substr(line, fence_pos + fence_run, 1) == fence_char) fence_run++ } - if (in_fence) { + if (!in_comment && in_fence) { print line if (fence_char == active_fence_char && fence_run >= active_fence_run) in_fence=0 next } - if (fence_run >= 3) { + fence_info=substr(line, fence_pos + fence_run) + valid_fence_info=(fence_char == "~" || index(fence_info, "`") == 0) + if (!in_comment && fence_run >= 3 && valid_fence_info) { in_fence=1 active_fence_char=fence_char active_fence_run=fence_run @@ -52,7 +54,13 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk ' continue } - if (substr(line, pos, 1) == "`") { + escaped=0 + escape_pos=pos - 1 + while (escape_pos >= 1 && substr(line, escape_pos, 1) == "\\") { + escaped++ + escape_pos-- + } + if (substr(line, pos, 1) == "`" && escaped % 2 == 0) { ticks=1 while (substr(line, pos + ticks, 1) == "`") ticks++ close_pos=pos + ticks diff --git a/tests/run b/tests/run index 2085280..6e4c456 100755 --- a/tests/run +++ b/tests/run @@ -150,6 +150,15 @@ check_contract "four-space indented backticks do not expose comments" \ check_contract "unequal backtick runs do not expose comments" \ $'`' \ "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" +check_contract "invalid backtick fence info does not expose comments" \ + $'```html`oops\n' \ + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" +check_contract "fences inside comments do not expose provenance" \ + $'' \ + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" +check_contract "escaped backticks do not hide a comment opener" \ + $'\\`' \ + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract_pass "inline code containing comment opener stays visible" \ $'Use `