Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/uri/rfc2396_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module PATTERN
# "a" | "b" | "c" | "d" | "e" | "f"
HEX = "a-fA-F\\d"
# escaped = "%" hex hex
ESCAPED = "%[#{HEX}]{2}"
ESCAPED = "%[#{HEX}][#{HEX}]"
# mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
# "(" | ")"
# unreserved = alphanum | mark
Expand Down Expand Up @@ -374,9 +374,11 @@ def initialize_pattern(opts = {})
# allowed too. Here is a replacement.
#
# IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
ret[:IPV4ADDR] = ipv4addr = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
dig3 = "\\d\\d?\\d?"
ret[:IPV4ADDR] = ipv4addr = "#{dig3}\\.#{dig3}\\.#{dig3}\\.#{dig3}"
# hex4 = 1*4HEXDIG
hex4 = "[#{PATTERN::HEX}]{1,4}"
hex = "[#{PATTERN::HEX}]"
hex4 = "#{hex}#{hex}?#{hex}?#{hex}?"
# lastpart = hex4 | IPv4address
lastpart = "(?:#{hex4}|#{ipv4addr})"
# hexseq1 = *( hex4 ":" ) hex4
Expand Down
9 changes: 9 additions & 0 deletions test/uri/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,13 @@ def test_rfc2822_make_regexp
assert_match(regexp, "http://example.com/")
refute_match(regexp, "https://example.com/")
end

def test_rfc2396_regexp_linear_time
omit "Regexp.linear_time? is not available" unless Regexp.respond_to?(:linear_time?)
URI::RFC2396_PARSER.regexp.each do |name, re|
assert Regexp.linear_time?(re), "regexp[#{name.inspect}] should be linear time"
end
assert Regexp.linear_time?(URI::RFC2396_PARSER.make_regexp)
assert Regexp.linear_time?(URI::RFC2396_PARSER.make_regexp(%w[http https]))
end
end
Loading