Skip to content

Commit

Permalink
Merge pull request #1474 from PombeirP/failing-sanitizer-spec
Browse files Browse the repository at this point in the history
Fix mismatched code span issue when sanitizing mentions
  • Loading branch information
greysteil authored Oct 27, 2019
2 parents a7dafb5 + ddf6a3e commit 82b9d2e
Show file tree
Hide file tree
Showing 3 changed files with 532 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@ class LinkAndMentionSanitizer
github\.com/(?<repo>#{GITHUB_USERNAME}/[^/\s]+)/
(?:issue|pull)s?/(?<number>\d+)
}x.freeze
CODEBLOCK_REGEX = /(`+).*?(\1)|~~~.*?~~~/m.freeze
# rubocop:disable Metrics/LineLength
# Context:
# - https://github.github.com/gfm/#fenced-code-block (``` or ~~~)
# (?<=\n|^) Positive look-behind to ensure we start at a line start
# (?>`{3,}|~{3,}) Atomic group marking the beginning of the block (3 or more chars)
# (?>\k<fenceopen>) Atomic group marking the end of the code block (same length as opening)
# - https://github.github.com/gfm/#code-span
# (?<codespanopen>`+) Capturing group marking the beginning of the span (1 or more chars)
# (?![^`]*?\n{2,}) Negative look-ahead to avoid empty lines inside code span
# (?:.|\n)*? Non-capturing group to consume code span content (non-eager)
# (?>\k<codespanopen>) Atomic group marking the end of the code span (same length as opening)
# rubocop:enable Metrics/LineLength
CODEBLOCK_REGEX = /
# fenced code block
(?<=\n|^)(?<fenceopen>(?>`{3,}|~{3,})).*?(?>\k<fenceopen>)|
# code span
(?<codespanopen>`+)(?![^`]*?\n{2,})(?:.|\n)*?(?>\k<codespanopen>)
/xm.freeze
# End of string
EOS_REGEX = /\z/.freeze

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
it { is_expected.to eq(text) }
end

context "with unmatched single code ticks previously" do
let(:text) { fixture("changelogs", "sentry.md") }
it { is_expected.to include("@&#8203;halkeye") }
end

context "that appears in codeblock quotes" do
let(:text) { "``` @model ||= 123```" }
it { is_expected.to eq(text) }
Expand Down
Loading

0 comments on commit 82b9d2e

Please sign in to comment.