-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve color regex #1021
Improve color regex #1021
Conversation
e5fca46
to
bfed529
Compare
@@ -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/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubocop requested this
@@ -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) } | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubocop
@@ -26,6 +26,7 @@ | |||
let(:num_columns) { 5 } | |||
let(:num_rows) { 8 } | |||
let(:gutter) { 10.0 } | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubocop
bfed529
to
0f5b15f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@brendanthomas1 Thank you for your contribution. This PR will be merged a bit later when I have some time to work on Prawn. |
lib/prawn/graphics/color.rb
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By adding a pipe here, you are allowing the pipe character too. The correct expression is:
/\A[0-9A-F]{6}\z/i
You can test this by running the following in irb:
/[0-9|A-F]/.match('|').inspect
vs
/[0-9A-F]/.match('|').inspect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'i' flag could be avoided by making it:
/\A[0-9a-fA-F]{6}\z/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mojavelinux !
0f5b15f
to
ed8520e
Compare
@brendanthomas1 I cherry-picked your commit into master. Thank you for your contribution. |
The current color regex uses
[0-F]
which allows all characters with a char code between 48-70. This would allow a user to pass in any of: ; < = > ? `
into their hex.