Skip to content

Commit

Permalink
FIX: don't break when posting invalid URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed Apr 19, 2018
1 parent 74b8125 commit 45850a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/topic_link.rb
Expand Up @@ -118,7 +118,7 @@ def self.extract_from(post)
.map do |u|
uri = begin
URI.parse(u.url)
rescue URI::InvalidURIError
rescue URI::Error
end

[u, uri]
Expand Down
8 changes: 8 additions & 0 deletions spec/models/topic_link_spec.rb
Expand Up @@ -169,6 +169,14 @@ def test_uri
end
end

context "email address" do
it "does not extract a link" do
post = topic.posts.create(user: user, raw: "Valid email: foo@bar.com\n\nInvalid email: rfc822;name@domain.com")
TopicLink.extract_from(post)
expect(topic.topic_links).to be_blank
end
end

context "mail link" do
let(:post) { topic.posts.create(user: user, raw: "[email]bar@example.com[/email]") }

Expand Down

1 comment on commit 45850a0

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/error-when-posting-invalid-email-address/85631/5

Please sign in to comment.