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 4, 2017
1 parent dc08857 commit bfed529
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
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
1 change: 1 addition & 0 deletions spec/prawn/document_grid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
let(:num_columns) { 5 }
let(:num_rows) { 8 }
let(:gutter) { 10.0 }

before do
pdf.define_grid(
columns: num_columns,
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
1 change: 1 addition & 0 deletions spec/prawn/stamp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe Prawn::Stamp do
describe 'create_stamp before any page is added' do
let(:pdf) { Prawn::Document.new(skip_page_creation: true) }

it 'works with the font class' do
# If anything goes wrong, Prawn::Errors::NotOnPage will be raised
pdf.create_stamp('my_stamp') do
Expand Down
2 changes: 1 addition & 1 deletion spec/prawn/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
pdf.text ' '
text = PDF::Inspector::Text.analyze(pdf.render)
# If anything is rendered to the page, it should be whitespace.
text.strings.each { |str| expect(str).to match(/\A\s*\z/) }
expect(text.strings).to all match(/\A\s*\z/)
end

it 'ignores call when string is nil' do
Expand Down

0 comments on commit bfed529

Please sign in to comment.