Skip to content
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

Stop parsing if garbage exists around UUID #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sho-h
Copy link

@sho-h sho-h commented Feb 2, 2016

UUIDTools::UUID.parse can parse string that has garbage around UUID.

s = SecureRandom.uuid # => "31a6b11d-06be-42b7-8800-53038da42ebe"
UUIDTools::UUID.parse("foo\n" + s + "\nbar") # => #<UUID:0x3fed7590a9dc UUID:31a6b11d-06be-42b7-8800-53038da42ebe>

This means UUIDTools::UUID.parse can't use for validation.

@@ -724,8 +724,8 @@ def self.convert_byte_string_to_int(byte_string)

##
# Constant Regexp that matches a UUID and captures its components.
UUID_REGEXP = Regexp.new("^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-" +
"([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{12})$")
UUID_REGEXP = Regexp.new("\\A([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use \ instead of + or << to concatenate those strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants