Skip to content

Commit eafc475

Browse files
authored
Merge pull request #132 from ruby/fix-uri-regexp-pattern
Restore constants like URI::REGEXP::PATTERN::IPV6ADDR
2 parents dd1dcd4 + 60a8bc1 commit eafc475

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lib/uri/common.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ def self.parser=(parser = RFC3986_PARSER)
3131
if Parser == RFC2396_Parser
3232
const_set("REGEXP", URI::RFC2396_REGEXP)
3333
const_set("PATTERN", URI::RFC2396_REGEXP::PATTERN)
34-
Parser.new.pattern.each_pair do |sym, str|
35-
unless REGEXP::PATTERN.const_defined?(sym)
36-
REGEXP::PATTERN.const_set(sym, str)
37-
end
38-
end
3934
end
4035

4136
Parser.new.regexp.each_pair do |sym, str|

lib/uri/rfc2396_parser.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,11 @@ def convert_to_uri(uri)
536536
end
537537

538538
end # class Parser
539+
540+
# Backward compatibility for URI::REGEXP::PATTERN::*
541+
RFC2396_Parser.new.pattern.each_pair do |sym, str|
542+
unless RFC2396_REGEXP::PATTERN.const_defined?(sym)
543+
RFC2396_REGEXP::PATTERN.const_set(sym, str)
544+
end
545+
end
539546
end # module URI

test/uri/test_common.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def setup
1010
def teardown
1111
end
1212

13+
class Foo
14+
include URI::REGEXP::PATTERN
15+
end
16+
1317
def test_fallback_constants
1418
orig_verbose = $VERBOSE
1519
$VERBOSE = nil
@@ -19,6 +23,8 @@ def test_fallback_constants
1923
assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI]
2024
assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN
2125
assert_equal URI::REGEXP, URI::RFC2396_REGEXP
26+
assert_equal URI::REGEXP::PATTERN, URI::RFC2396_REGEXP::PATTERN
27+
assert_equal Foo::IPV4ADDR, URI::RFC2396_REGEXP::PATTERN::IPV4ADDR
2228
ensure
2329
$VERBOSE = orig_verbose
2430
end
@@ -34,6 +40,7 @@ def test_parser_switch
3440
assert defined?(URI::REGEXP)
3541
assert defined?(URI::PATTERN)
3642
assert defined?(URI::PATTERN::ESCAPED)
43+
assert defined?(URI::REGEXP::PATTERN::IPV6ADDR)
3744

3845
URI.parser = URI::RFC3986_PARSER
3946

0 commit comments

Comments
 (0)