Commit ce36171d62852719508d450b126fd53516c16988

Authored by Stephen Crosby
2 parents 47085886 ee8b1d1c
Exists in master and in 1 other branch production

Merge pull request #923 from steveyken/master

Fixed notice parsing error when request['url'] is 'file:///...'
app/models/notice.rb
@@ -74,7 +74,7 @@ class Notice @@ -74,7 +74,7 @@ class Notice
74 74
75 def host 75 def host
76 uri = url && URI.parse(url) 76 uri = url && URI.parse(url)
77 - uri.blank? ? "N/A" : uri.host 77 + uri && uri.host || "N/A"
78 rescue URI::InvalidURIError 78 rescue URI::InvalidURIError
79 "N/A" 79 "N/A"
80 end 80 end
spec/models/notice_spec.rb
@@ -89,6 +89,11 @@ describe Notice, type: 'model' do @@ -89,6 +89,11 @@ describe Notice, type: 'model' do
89 end 89 end
90 90
91 it "returns 'N/A' when url is not valid" do 91 it "returns 'N/A' when url is not valid" do
  92 + notice = Fabricate.build(:notice, :request => {'url' => "file:///path/to/some/resource/12"})
  93 + expect(notice.host).to eq 'N/A'
  94 + end
  95 +
  96 + it "returns 'N/A' when url is not valid" do
92 notice = Fabricate.build(:notice, :request => {'url' => "some string"}) 97 notice = Fabricate.build(:notice, :request => {'url' => "some string"})
93 expect(notice.host).to eq 'N/A' 98 expect(notice.host).to eq 'N/A'
94 end 99 end