Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mismatched code span issue when sanitizing mentions #1474

Merged
merged 2 commits into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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