Fix 500er when calling protocol handler with invalid URL
This commit is contained in:
parent
035b6f39fc
commit
91aae4d755
2 changed files with 18 additions and 4 deletions
|
|
@ -10,7 +10,9 @@ class DiasporaLinkService
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_fetch_entity
|
def find_or_fetch_entity
|
||||||
entity_finder.find || fetch_entity
|
if type && guid
|
||||||
|
entity_finder.find || fetch_entity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -38,8 +40,8 @@ class DiasporaLinkService
|
||||||
def parse
|
def parse
|
||||||
normalize
|
normalize
|
||||||
match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link)
|
match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link)
|
||||||
@author = match[1]
|
if match
|
||||||
@type = match[2]
|
@author, @type, @guid = match.captures
|
||||||
@guid = match[3]
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,17 @@ describe DiasporaLinkService do
|
||||||
expect(service.find_or_fetch_entity).to be_nil
|
expect(service.find_or_fetch_entity).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with invalid links" do
|
||||||
|
it "returns nil when the link is invalid" do
|
||||||
|
service = described_class.new("web+diaspora://something_invalid")
|
||||||
|
expect(service.find_or_fetch_entity).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil when the author is valid, but rest of the link is invalid" do
|
||||||
|
service = described_class.new("web+diaspora://#{alice.diaspora_handle}/foo/bar")
|
||||||
|
expect(service.find_or_fetch_entity).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue