FIX: rescue InvalidURIError when removing user ids from links
This commit is contained in:
parent
84cfe30c1f
commit
6f5d7f987e
|
@ -598,7 +598,11 @@ class CookedPostProcessor
|
||||||
|
|
||||||
def remove_user_ids
|
def remove_user_ids
|
||||||
@doc.css("a[href]").each do |a|
|
@doc.css("a[href]").each do |a|
|
||||||
uri = URI(a["href"])
|
uri = begin
|
||||||
|
URI(a["href"])
|
||||||
|
rescue URI::Error
|
||||||
|
next
|
||||||
|
end
|
||||||
next if uri.hostname != Discourse.current_hostname
|
next if uri.hostname != Discourse.current_hostname
|
||||||
|
|
||||||
query = Rack::Utils.parse_nested_query(uri.query)
|
query = Rack::Utils.parse_nested_query(uri.query)
|
||||||
|
|
|
@ -1047,6 +1047,8 @@ describe CookedPostProcessor do
|
||||||
a tricky link to a topic: #{topic.url}?bob=bob;u=sam&jane=jane
|
a tricky link to a topic: #{topic.url}?bob=bob;u=sam&jane=jane
|
||||||
|
|
||||||
link to an external topic: https://google.com/?u=bar
|
link to an external topic: https://google.com/?u=bar
|
||||||
|
|
||||||
|
a malformed url: https://www.example.com/#123#4
|
||||||
RAW
|
RAW
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1058,6 +1060,7 @@ describe CookedPostProcessor do
|
||||||
expect(cpp.html).to have_tag('a', with: { href: topic.url })
|
expect(cpp.html).to have_tag('a', with: { href: topic.url })
|
||||||
expect(cpp.html).to have_tag('a', with: { href: "#{topic.url}?bob=bob&jane=jane" })
|
expect(cpp.html).to have_tag('a', with: { href: "#{topic.url}?bob=bob&jane=jane" })
|
||||||
expect(cpp.html).to have_tag('a', with: { href: "https://google.com/?u=bar" })
|
expect(cpp.html).to have_tag('a', with: { href: "https://google.com/?u=bar" })
|
||||||
|
expect(cpp.html).to have_tag('a', with: { href: "https://www.example.com/#123#4" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue