Class: Bundler::URI::RFC3986_Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb

Overview

:nodoc:

Constant Summary collapse

HOST =

Bundler::URI defined in RFC3986

%r[
  (?<IP-literal>\[(?:
      (?<IPv6address>
        (?:\h{1,4}:){6}
        (?<ls32>\h{1,4}:\h{1,4}
        | (?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)
            \.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>)
        )
      | ::(?:\h{1,4}:){5}\g<ls32>
      | \h{1,4}?::(?:\h{1,4}:){4}\g<ls32>
      | (?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>
      | (?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>
      | (?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>
      | (?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>
      | (?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}
      | (?:(?:\h{1,4}:){,6}\h{1,4})?::
      )
    | (?<IPvFuture>v\h++\.[!$&-.0-9:;=A-Z_a-z~]++)
    )\])
| \g<IPv4address>
| (?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*+)
]x
USERINFO =
/(?:%\h\h|[!$&-.0-9:;=A-Z_a-z~])*+/
SCHEME =
%r[[A-Za-z][+\-.0-9A-Za-z]*+].source
SEG =
%r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/])].source
SEG_NC =
%r[(?:%\h\h|[!$&-.0-9;=@A-Z_a-z~])].source
FRAGMENT =
%r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+].source
RFC3986_URI =
%r[\A
(?<seg>#{SEG}){0}
(?<Bundler::URI>
  (?<scheme>#{SCHEME}):
  (?<hier-part>//
    (?<authority>
      (?:(?<userinfo>#{USERINFO.source})@)?
      (?<host>#{HOST.source.delete(" \n")})
      (?::(?<port>\d*+))?
    )
    (?<path-abempty>(?:/\g<seg>*+)?)
  | (?<path-absolute>/((?!/)\g<seg>++)?)
  | (?<path-rootless>(?!/)\g<seg>++)
  | (?<path-empty>)
  )
  (?:\?(?<query>[^\#]*+))?
  (?:\#(?<fragment>#{FRAGMENT}))?
)\z]x
RFC3986_relative_ref =
%r[\A
(?<seg>#{SEG}){0}
(?<relative-ref>
  (?<relative-part>//
    (?<authority>
      (?:(?<userinfo>#{USERINFO.source})@)?
      (?<host>#{HOST.source.delete(" \n")}(?<!/))?
      (?::(?<port>\d*+))?
    )
    (?<path-abempty>(?:/\g<seg>*+)?)
  | (?<path-absolute>/\g<seg>*+)
  | (?<path-noscheme>#{SEG_NC}++(?:/\g<seg>*+)?)
  | (?<path-empty>)
  )
  (?:\?(?<query>[^#]*+))?
  (?:\#(?<fragment>#{FRAGMENT}))?
)\z]x
@@to_s =
Kernel.instance_method(:to_s)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRFC3986_Parser

Returns a new instance of RFC3986_Parser.



73
74
75
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 73

def initialize
  @regexp = default_regexp.each_value(&:freeze).freeze
end

Instance Attribute Details

#regexpObject (readonly)

Returns the value of attribute regexp.



71
72
73
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 71

def regexp
  @regexp
end

Instance Method Details

#escape(str, unsafe = nil) ⇒ Object

Compatibility for RFC2396 parser



156
157
158
159
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 156

def escape(str, unsafe = nil) # :nodoc:
  warn "Bundler::URI::RFC3986_PARSER.escape is obsolete. Use Bundler::URI::RFC2396_PARSER.escape explicitly.", uplevel: 1 if $VERBOSE
  unsafe ? RFC2396_PARSER.escape(str, unsafe) : RFC2396_PARSER.escape(str)
end

#extract(str, schemes = nil, &block) ⇒ Object

Compatibility for RFC2396 parser



144
145
146
147
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 144

def extract(str, schemes = nil, &block) # :nodoc:
  warn "Bundler::URI::RFC3986_PARSER.extract is obsolete. Use Bundler::URI::RFC2396_PARSER.extract explicitly.", uplevel: 1 if $VERBOSE
  RFC2396_PARSER.extract(str, schemes, &block)
end

#inspectObject



169
170
171
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 169

def inspect
  @@to_s.bind_call(self)
end

#join(*uris) ⇒ Object

:nodoc:



138
139
140
141
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 138

def join(*uris) # :nodoc:
  uris[0] = convert_to_uri(uris[0])
  uris.inject :merge
end

#make_regexp(schemes = nil) ⇒ Object

Compatibility for RFC2396 parser



150
151
152
153
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 150

def make_regexp(schemes = nil) # :nodoc:
  warn "Bundler::URI::RFC3986_PARSER.make_regexp is obsolete. Use Bundler::URI::RFC2396_PARSER.make_regexp explicitly.", uplevel: 1 if $VERBOSE
  RFC2396_PARSER.make_regexp(schemes)
end

#parse(uri) ⇒ Object

:nodoc:



134
135
136
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 134

def parse(uri) # :nodoc:
  Bundler::URI.for(*self.split(uri), self)
end

#split(uri) ⇒ Object

:nodoc:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 77

def split(uri) #:nodoc:
  begin
    uri = uri.to_str
  rescue NoMethodError
    raise InvalidURIError, "bad Bundler::URI (is not Bundler::URI?): #{uri.inspect}"
  end
  uri.ascii_only? or
    raise InvalidURIError, "Bundler::URI must be ascii only #{uri.dump}"
  if m = RFC3986_URI.match(uri)
    query = m["query"]
    scheme = m["scheme"]
    opaque = m["path-rootless"]
    if opaque
      opaque << "?#{query}" if query
      [ scheme,
        nil, # userinfo
        nil, # host
        nil, # port
        nil, # registry
        nil, # path
        opaque,
        nil, # query
        m["fragment"]
      ]
    else # normal
      [ scheme,
        m["userinfo"],
        m["host"],
        m["port"],
        nil, # registry
        (m["path-abempty"] ||
         m["path-absolute"] ||
         m["path-empty"]),
        nil, # opaque
        query,
        m["fragment"]
      ]
    end
  elsif m = RFC3986_relative_ref.match(uri)
    [ nil, # scheme
      m["userinfo"],
      m["host"],
      m["port"],
      nil, # registry,
      (m["path-abempty"] ||
       m["path-absolute"] ||
       m["path-noscheme"] ||
       m["path-empty"]),
      nil, # opaque
      m["query"],
      m["fragment"]
    ]
  else
    raise InvalidURIError, "bad Bundler::URI (is not Bundler::URI?): #{uri.inspect}"
  end
end

#unescape(str, escaped = nil) ⇒ Object

Compatibility for RFC2396 parser



162
163
164
165
# File 'lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb', line 162

def unescape(str, escaped = nil) # :nodoc:
  warn "Bundler::URI::RFC3986_PARSER.unescape is obsolete. Use Bundler::URI::RFC2396_PARSER.unescape explicitly.", uplevel: 1 if $VERBOSE
  escaped ? RFC2396_PARSER.unescape(str, escaped) : RFC2396_PARSER.unescape(str)
end