mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: correctly escape regex url
duplicate link detection could fail in certain cases
This commit is contained in:
parent
6428aa5b1f
commit
6300d978e2
|
@ -157,7 +157,8 @@ class PlainTextToMarkdown
|
|||
.keep_if { |_, urls | urls.length > 1 }
|
||||
.keys.each do |url|
|
||||
|
||||
text.gsub!(Regexp.new(%Q|#{url}(\s*[()\\[\\]<>«»'"“”‘’]?#{url}[()\\[\\]<>«»'"“”‘’]?)|, Regexp::IGNORECASE), url)
|
||||
escaped = Regexp.escape(url)
|
||||
text.gsub!(Regexp.new(%Q|#{escaped}(\s*[()\\[\\]<>«»'"“”‘’]?#{escaped}[()\\[\\]<>«»'"“”‘’]?)|, Regexp::IGNORECASE), url)
|
||||
end
|
||||
|
||||
text
|
||||
|
|
|
@ -160,6 +160,9 @@ describe PlainTextToMarkdown do
|
|||
|
||||
context "links" do
|
||||
it "removes duplicate links" do
|
||||
expect(to_markdown("foo https://www.example.com/foo.html?a=1 <https://www.example.com/foo.html?a=1> bar"))
|
||||
.to eq("foo https://www.example.com/foo.html?a=1 bar")
|
||||
|
||||
expect(to_markdown("foo https://www.example.com/foo.html <https://www.example.com/foo.html> bar"))
|
||||
.to eq("foo https://www.example.com/foo.html bar")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user