Skip to content

Commit

Permalink
Merge branch 'rfc3986_scheme_validation' of github.com:ptoomey3/addre…
Browse files Browse the repository at this point in the history
…ssable into ptoomey3-rfc3986_scheme_validation
  • Loading branch information
sporkmonger committed Dec 7, 2015
2 parents cf8cc7d + 4979360 commit e2325b8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/addressable/uri.rb
Expand Up @@ -862,7 +862,7 @@ def scheme=(new_scheme)
elsif new_scheme
new_scheme = new_scheme.to_str
end
if new_scheme && new_scheme !~ /[a-z][a-z0-9\.\+\-]*/i
if new_scheme && new_scheme !~ /\A[a-z][a-z0-9\.\+\-]*\z/i
raise InvalidURIError, "Invalid scheme format."
end
@scheme = new_scheme
Expand Down
51 changes: 42 additions & 9 deletions spec/addressable/uri_spec.rb
Expand Up @@ -243,6 +243,48 @@ def to_s
end).to raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if the scheme begins with a digit" do
(lambda do
@uri.scheme = "1scheme"
end).should raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if the scheme begins with a plus" do
(lambda do
@uri.scheme = "+scheme"
end).should raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if the scheme begins with a dot" do
(lambda do
@uri.scheme = ".scheme"
end).should raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if the scheme begins with a dash" do
(lambda do
@uri.scheme = "-scheme"
end).should raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if the scheme contains an illegal character" do
(lambda do
@uri.scheme = "scheme!"
end).should raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if the scheme contains whitespace" do
(lambda do
@uri.scheme = "sch eme"
end).should raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if the scheme contains a newline" do
(lambda do
@uri.scheme = "sch\neme"
end).should raise_error(Addressable::URI::InvalidURIError)
end

it "should raise an error if set into an invalid state" do
expect(lambda do
@uri.user = "user"
Expand Down Expand Up @@ -3632,15 +3674,6 @@ def to_s
expect(@uri.to_str).to eq(
"ftp://user:pass@example.com/path/to/resource?query=x#fragment"
)
@uri.scheme = "bogus!"
expect(@uri.scheme).to eq("bogus!")
expect(@uri.normalized_scheme).to eq("bogus%21")
expect(@uri.normalize.to_s).to eq(
"bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
)
expect(@uri.normalize.to_str).to eq(
"bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
)
end

it "should have the correct site segment after assignment" do
Expand Down

0 comments on commit e2325b8

Please sign in to comment.