Skip to content

Commit e7ec04b

Browse files
committed
Use RFC2396 URI parser
As a side-effect of updating activesupport to v8, the uri gem was added with its latest version (1.0.2). Since v1 the default URI parser was switched from RFC2396 to RFC3986. Thus the following changes were done: - URI::DEFAULT_PARSER replaced with URI::RFC2396_PARSER - URI::REGEXP replaced with URI::RFC2396_REGEXP - As some other gems (e.g. fog-local) wrongly assume that URI::DEFAULT_PARSER is the RFC2396 variant, the default parser was changed with a monkey patch.
1 parent b30ea21 commit e7ec04b

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

app/messages/validators/url_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module VCAP::CloudController::Validators
55
class UrlValidator < ActiveModel::Validator
66
def validate(record)
7-
if URI::DEFAULT_PARSER.make_regexp(%w[https http]).match?(record.url.to_s)
7+
if URI::RFC2396_PARSER.make_regexp(%w[https http]).match?(record.url.to_s)
88
record.errors.add(:url, 'must not contain authentication') if URI(record.url).user
99
else
1010
record.errors.add(:url, "'#{record.url}' must be a valid url")

lib/cloud_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ module VCAP::CloudController; end
117117
require 'cloud_controller/errands/rotate_database_key'
118118

119119
require 'services'
120+
121+
# Switch default URI parser globally as some other gems (e.g. fog-local) wrongly assume that URI::DEFAULT_PARSER is the RFC2396 variant.
122+
module URI
123+
remove_const(:DEFAULT_PARSER) if const_defined?(:DEFAULT_PARSER)
124+
const_set(:DEFAULT_PARSER, RFC2396_PARSER)
125+
126+
self.parser = RFC2396_PARSER
127+
end

lib/cloud_controller/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def escape_userinfo(value)
9595
end
9696

9797
def valid_in_userinfo?(value)
98-
URI::REGEXP::PATTERN::USERINFO.match(value)
98+
URI::RFC2396_REGEXP::PATTERN::USERINFO.match(value)
9999
end
100100
end
101101

lib/sequel_plugins/vcap_validations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module InstanceMethods
66
def validates_url(attr, opts={})
77
return unless send(attr)
88

9-
validates_format(URI::DEFAULT_PARSER.make_regexp(%w[http https]), attr, message: opts.fetch(:message, :url))
9+
validates_format(URI::RFC2396_PARSER.make_regexp(%w[http https]), attr, message: opts.fetch(:message, :url))
1010
end
1111
end
1212
end

lib/utils/uri_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module UriUtils
88
class InvalidDockerURI < StandardError; end
99

1010
def self.is_uri?(candidate)
11-
!!(candidate.is_a?(String) && /\A#{URI::DEFAULT_PARSER.make_regexp}\Z/ =~ candidate && URI(candidate))
11+
!!(candidate.is_a?(String) && /\A#{URI::RFC2396_PARSER.make_regexp}\Z/ =~ candidate && URI(candidate))
1212
rescue StandardError
1313
false
1414
end

lib/vcap/rest_api/message.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def self.schema_doc(schema)
5555
schema.deparse
5656
end
5757

58-
URL = UrlDecorator.new(URI::DEFAULT_PARSER.make_regexp(%w[http https]))
59-
HTTPS_URL = HttpsUrlDecorator.new(URI::DEFAULT_PARSER.make_regexp('https'))
60-
GIT_URL = GitUrlDecorator.new(URI::DEFAULT_PARSER.make_regexp(%w[http https git]))
58+
URL = UrlDecorator.new(URI::RFC2396_PARSER.make_regexp(%w[http https]))
59+
HTTPS_URL = HttpsUrlDecorator.new(URI::RFC2396_PARSER.make_regexp('https'))
60+
GIT_URL = GitUrlDecorator.new(URI::RFC2396_PARSER.make_regexp(%w[http https git]))
6161

6262
# The block will be evaluated in the context of the schema validator used
6363
# by class `JsonMessage` viz. `Membrane`.

0 commit comments

Comments
 (0)