A platform for community discussion. Free, open, simple.
FIX: rescue InvalidURIError when removing user ids from links
Arpit Jalan6f5d7f987e05
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 2094913a951..e78fa9c6366 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -598,7 +598,11 @@ class CookedPostProcessordef remove_user_ids@doc.css("a[href]").each do |a|- uri = URI(a["href"])+ uri = begin+ URI(a["href"])+ rescue URI::Error+ next+ endnext if uri.hostname != Discourse.current_hostnamequery = Rack::Utils.parse_nested_query(uri.query)diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 352cc68d487..19159fdc7a6 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -1047,6 +1047,8 @@ describe CookedPostProcessor doa tricky link to a topic: #{topic.url}?bob=bob;u=sam&jane=janelink to an external topic: https://google.com/?u=bar++ a malformed url: https://www.example.com/#123#4RAWend@@ -1058,6 +1060,7 @@ describe CookedPostProcessor doexpect(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: "https://google.com/?u=bar" })+ expect(cpp.html).to have_tag('a', with: { href: "https://www.example.com/#123#4" })endend