From 9e45633527c3b76bc824e48f820d95be6d0447ac Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Fri, 4 Nov 2016 11:25:33 -0700 Subject: [PATCH] Adding tests for origin assignment errors. --- spec/addressable/uri_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb index 81a8cd86..dafc7767 100644 --- a/spec/addressable/uri_spec.rb +++ b/spec/addressable/uri_spec.rb @@ -1803,7 +1803,7 @@ def to_s end it "should have the same hash as http://EXAMPLE.com after assignment" do - @uri.host = "EXAMPLE.com" + @uri.origin = "http://EXAMPLE.com" expect(@uri.hash).to eq(Addressable::URI.parse("http://EXAMPLE.com").hash) end @@ -1811,6 +1811,18 @@ def to_s expect(@uri.hash).not_to eq(Addressable::URI.parse("http://EXAMPLE.com").hash) end + it "should not allow origin assignment without scheme" do + expect(lambda do + @uri.origin = "example.com" + end).to raise_error(Addressable::URI::InvalidURIError) + end + + it "should not allow origin assignment without host" do + expect(lambda do + @uri.origin = "http://" + end).to raise_error(Addressable::URI::InvalidURIError) + end + # Section 6.2.3 of RFC 3986 it "should be equivalent to http://example.com/" do expect(@uri).to eq(Addressable::URI.parse("http://example.com/"))