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

Restore constants like URI::REGEXP::PATTERN::IPV6ADDR #132

Merged
merged 2 commits into from
Nov 14, 2024
Merged
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
5 changes: 0 additions & 5 deletions lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ def self.parser=(parser = RFC3986_PARSER)
if Parser == RFC2396_Parser
const_set("REGEXP", URI::RFC2396_REGEXP)
const_set("PATTERN", URI::RFC2396_REGEXP::PATTERN)
Parser.new.pattern.each_pair do |sym, str|
unless REGEXP::PATTERN.const_defined?(sym)
REGEXP::PATTERN.const_set(sym, str)
end
end
end

Parser.new.regexp.each_pair do |sym, str|
Expand Down
7 changes: 7 additions & 0 deletions lib/uri/rfc2396_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,11 @@ def convert_to_uri(uri)
end

end # class Parser

# Backward compatibility for URI::REGEXP::PATTERN::*
RFC2396_Parser.new.pattern.each_pair do |sym, str|
unless RFC2396_REGEXP::PATTERN.const_defined?(sym)
RFC2396_REGEXP::PATTERN.const_set(sym, str)
end
end
end # module URI
7 changes: 7 additions & 0 deletions test/uri/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def setup
def teardown
end

class Foo
include URI::REGEXP::PATTERN
end

def test_fallback_constants
orig_verbose = $VERBOSE
$VERBOSE = nil
Expand All @@ -19,6 +23,8 @@ def test_fallback_constants
assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI]
assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN
assert_equal URI::REGEXP, URI::RFC2396_REGEXP
assert_equal URI::REGEXP::PATTERN, URI::RFC2396_REGEXP::PATTERN
assert_equal Foo::IPV4ADDR, URI::RFC2396_REGEXP::PATTERN::IPV4ADDR
ensure
$VERBOSE = orig_verbose
end
Expand All @@ -34,6 +40,7 @@ def test_parser_switch
assert defined?(URI::REGEXP)
assert defined?(URI::PATTERN)
assert defined?(URI::PATTERN::ESCAPED)
assert defined?(URI::REGEXP::PATTERN::IPV6ADDR)

URI.parser = URI::RFC3986_PARSER

Expand Down