Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Require URIs to be absolute to be valid. This fixes issue #122.

  • Loading branch information...
commit acbf5e8c75fc637dcf97ef414217e82c72b544ef 1 parent 469cc3a
@gkellogg gkellogg authored
Showing with 20 additions and 16 deletions.
  1. +6 −2 lib/rdf/model/uri.rb
  2. +14 −14 spec/model_uri_spec.rb
View
8 lib/rdf/model/uri.rb
@@ -198,7 +198,7 @@ def length
alias_method :size, :length
##
- # Determine if the URI is avalid according to RFC3987
+ # Determine if the URI is a valid according to RFC3987
#
# Note, for Ruby versions < 1.9, this always returns true.
#
@@ -207,7 +207,7 @@ def length
def valid?
# As Addressable::URI does not perform adequate validation, validate
# relative to RFC3987
- to_s.match(RDF::URI::IRI) || to_s.match(RDF::URI::IRELATIVE_REF) || false
+ to_s.match(RDF::URI::IRI) || false
end
##
@@ -263,12 +263,15 @@ def canonicalize!
# @see RDF::URI#+
# @param [Array<String, RDF::URI, #to_s>] uris
# @return [RDF::URI]
+ # @raise [ArgumentError] if the resulting URI is invalid
def join(*uris)
result = @uri.dup
uris.each do |uri|
result = result.join(uri)
end
self.class.new(result)
+ rescue Addressable::URI::InvalidURIError => e
+ raise ArgumentError, e.message
end
##
@@ -294,6 +297,7 @@ def join(*uris)
#
# @param [Any] fragment A URI fragment to be appended to this URI
# @return [RDF::URI]
+ # @raise [ArgumentError] if the URI is invalid
# @see RDF::URI#+
# @see RDF::URI#join
# @see <http://tools.ietf.org/html/rfc3986#section-5.2>
View
28 spec/model_uri_spec.rb
@@ -112,33 +112,33 @@
end
end
- it "validates irelative-ref with authority #{mod}" do
+ it "invalidates irelative-ref with authority #{mod}" do
refs.each do |c|
- RDF::URI("//auth/#{fmt}" % [c, c, c]).should be_valid
+ RDF::URI("//auth/#{fmt}" % [c, c, c]).should_not be_valid
end
end
- it "validates irelative-ref with authority and port #{mod}" do
+ it "invalidates irelative-ref with authority and port #{mod}" do
refs.each do |c|
- RDF::URI("//auth:123/#{fmt}" % [c, c, c]).should be_valid
+ RDF::URI("//auth:123/#{fmt}" % [c, c, c]).should_not be_valid
end
end
- it "validates irelative-ref with ipath-absolute #{mod}" do
+ it "invalidates irelative-ref with ipath-absolute #{mod}" do
refs.each do |c|
- RDF::URI("/#{fmt}" % [c, c, c]).should be_valid
- RDF::URI("/#{fmt}" % ["#{c}/", c, c]).should be_valid
- RDF::URI("/#{fmt}" % ["#{c}/#{c}", c, c]).should be_valid
+ RDF::URI("/#{fmt}" % [c, c, c]).should_not be_valid
+ RDF::URI("/#{fmt}" % ["#{c}/", c, c]).should_not be_valid
+ RDF::URI("/#{fmt}" % ["#{c}/#{c}", c, c]).should_not be_valid
end
end
- it "validates irelative-ref with ipath-noscheme #{mod}" do
+ it "invalidates irelative-ref with ipath-noscheme #{mod}" do
refs.each do |c|
- RDF::URI("#{fmt}" % [c, c, c]).should be_valid
- RDF::URI("#{fmt}" % ["#{c}/", c, c]).should be_valid
- RDF::URI("#{fmt}" % ["#{c}/#{c}", c, c]).should be_valid
+ RDF::URI("#{fmt}" % [c, c, c]).should_not be_valid
+ RDF::URI("#{fmt}" % ["#{c}/", c, c]).should_not be_valid
+ RDF::URI("#{fmt}" % ["#{c}/#{c}", c, c]).should_not be_valid
end
end
- it "validates irelative-ref with ipath-empty #{mod}" do
+ it "invalidates irelative-ref with ipath-empty #{mod}" do
refs.each do |c|
- RDF::URI("#{fmt}" % ["", c, c]).should be_valid
+ RDF::URI("#{fmt}" % ["", c, c]).should_not be_valid
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.