Skip to content

Commit

Permalink
Improve color regex
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanthomas1 committed Apr 6, 2017
1 parent 101f681 commit 0f5b15f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/prawn/graphics/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def process_color(*color)
def color_type(color)
case color
when String
if color =~ /\A[0-F]{6}\z/i
if color =~ /\A[0-9|A-F]{6}\z/i
:RGB
else
raise ArgumentError, "Unknown type of color: #{color.inspect}"
Expand Down
4 changes: 4 additions & 0 deletions spec/prawn/graphics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@
expect { pdf.fill_color 'zcff00' }.to raise_error(ArgumentError)
end

it 'raises an error for a color string with invalid characters' do
expect { pdf.fill_color 'f0f0f?' }.to raise_error(ArgumentError)
end

it 'resets the colors on each new page if they have been defined' do
pdf.fill_color 'ccff00'

Expand Down

0 comments on commit 0f5b15f

Please sign in to comment.