Skip to content

Commit

Permalink
Merge pull request #3 from porras/exceptions
Browse files Browse the repository at this point in the history
Raise specific exceptions
  • Loading branch information
dball committed Feb 18, 2014
2 parents 605ec4a + 2b2dda3 commit 378baa9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/data_uri/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(*args)
if args.length == 1
uri = args.first.to_s
unless uri.match(/^data:/)
raise 'Invalid Data URI: ' + args.first.inspect
raise URI::InvalidURIError.new('Invalid Data URI: ' + args.first.inspect)
end
@scheme = 'data'
@opaque = uri[5 .. -1]
Expand All @@ -34,7 +34,7 @@ def initialize(*args)
@data = @data[7 .. -1]
end
unless /^,/.match(@data)
raise 'Invalid data URI'
raise URI::InvalidURIError.new('Invalid data URI')
end
@data = @data[1 .. -1]
@data = base64 ? Base64.decode64(@data) : URI.decode(@data)
Expand Down
7 changes: 7 additions & 0 deletions test/test_data_uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@

end

describe "an invalid data URI" do
it "should raise an error" do
proc { URI::Data.new("This is not a data URI") }.must_raise(URI::InvalidURIError)
proc { URI::Data.new("data:Neither this") }.must_raise(URI::InvalidURIError)
end
end

end

describe "building" do
Expand Down

0 comments on commit 378baa9

Please sign in to comment.