uri-whatwg_parser 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +0 -1
- data/Rakefile +1 -0
- data/lib/uri/whatwg_parser/generic.rb +54 -45
- data/lib/uri/whatwg_parser/host_parser.rb +1 -3
- data/lib/uri/whatwg_parser/version.rb +1 -1
- data/lib/uri/whatwg_parser.rb +114 -50
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ae0566e4902f0c52f40969d4b55ae40ac98b075bae062d8167895e847e91854
|
|
4
|
+
data.tar.gz: 1c9c1a764beb16e6719822138df7ef36fe5f02423052b4f436ae164a70eb7cab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d6dcb5018a93cd1f9a17ed84e5d409a0d6413efd405e50ea80f46169ad4b1970dd3e8732da209171c44a2f1a672f7e12b6914f1c5efa95ed882644a4e86393c1
|
|
7
|
+
data.tar.gz: 69e9afe795ab64751158bf69665de207649119c42f46a1aee9f34faea73a3756d1d4f4c2b5ffd22eab159c932056fbf1820f6dfc2855015d57dfb0c83910185b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -11,6 +11,7 @@ end
|
|
|
11
11
|
task :download_wpt_resources do
|
|
12
12
|
Dir.chdir "test/resources" do
|
|
13
13
|
system("curl -O https://raw.githubusercontent.com/web-platform-tests/wpt/master/url/resources/urltestdata.json", exception: true)
|
|
14
|
+
system("curl -O https://raw.githubusercontent.com/web-platform-tests/wpt/master/url/resources/setters_tests.json", exception: true)
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
@@ -10,6 +10,10 @@ module URI
|
|
|
10
10
|
fragment,
|
|
11
11
|
parser = DEFAULT_PARSER,
|
|
12
12
|
arg_check = false)
|
|
13
|
+
|
|
14
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
15
|
+
return super if registry
|
|
16
|
+
|
|
13
17
|
@scheme = nil
|
|
14
18
|
@user = nil
|
|
15
19
|
@password = nil
|
|
@@ -33,91 +37,96 @@ module URI
|
|
|
33
37
|
self.set_path("") if !@path && !@opaque
|
|
34
38
|
DEFAULT_PARSER.parse(to_s) if arg_check
|
|
35
39
|
|
|
36
|
-
if registry
|
|
37
|
-
raise InvalidURIError,
|
|
38
|
-
"the scheme #{@scheme} does not accept registry part: #{registry} (or bad hostname?)"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
40
|
@scheme&.freeze
|
|
42
41
|
self.set_port(self.default_port) if self.default_port && !@port
|
|
43
42
|
end
|
|
44
43
|
|
|
45
|
-
|
|
46
44
|
def merge(oth)
|
|
47
45
|
URI::DEFAULT_PARSER.join(self.to_s, oth.to_s)
|
|
48
46
|
end
|
|
49
47
|
alias + merge
|
|
50
48
|
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
true
|
|
55
|
-
end
|
|
49
|
+
def scheme=(v)
|
|
50
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
51
|
+
return if v.nil? || v.empty?
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
parse_result = URI::DEFAULT_PARSER.split("#{v}:", url: self, state_override: :scheme_start_state)
|
|
54
|
+
set_scheme(parse_result[0])
|
|
55
|
+
set_port(parse_result[3])
|
|
56
|
+
end
|
|
61
57
|
|
|
58
|
+
def user=(v)
|
|
59
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
62
60
|
return v unless v
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
if host.nil? || host.empty? || scheme == "file"
|
|
63
|
+
raise InvalidURIError, "cannot set user when host is nil or file schme"
|
|
64
|
+
end
|
|
65
|
+
set_user(URI::DEFAULT_PARSER.encode_userinfo(v))
|
|
67
66
|
end
|
|
68
67
|
|
|
69
|
-
def
|
|
70
|
-
|
|
71
|
-
raise InvalidURIError, "cannot set password with opaque"
|
|
72
|
-
end
|
|
68
|
+
def password=(v)
|
|
69
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
73
70
|
return v unless v
|
|
74
71
|
|
|
75
|
-
if
|
|
76
|
-
raise InvalidURIError, "password
|
|
72
|
+
if host.nil? || host.empty? || scheme == "file"
|
|
73
|
+
raise InvalidURIError, "cannot set password when host is nil or file schme"
|
|
77
74
|
end
|
|
78
|
-
|
|
79
|
-
self.set_password(v)
|
|
80
|
-
DEFAULT_PARSER.parse(to_s)
|
|
81
|
-
true
|
|
75
|
+
set_password(URI::DEFAULT_PARSER.encode_userinfo(v))
|
|
82
76
|
end
|
|
83
77
|
|
|
84
|
-
def
|
|
85
|
-
return
|
|
78
|
+
def host=(v)
|
|
79
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
80
|
+
return if v.nil?
|
|
86
81
|
|
|
87
82
|
if @opaque
|
|
88
83
|
raise InvalidURIError, "cannot set host with registry or opaque"
|
|
89
84
|
end
|
|
90
85
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
parse_result = URI::DEFAULT_PARSER.split(v.to_s, url: self, state_override: :host_state)
|
|
87
|
+
set_host(parse_result[2])
|
|
88
|
+
set_port(parse_result[3])
|
|
94
89
|
end
|
|
95
90
|
|
|
96
|
-
def
|
|
97
|
-
return
|
|
91
|
+
def port=(v)
|
|
92
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
93
|
+
return if v.nil?
|
|
98
94
|
|
|
99
|
-
if
|
|
100
|
-
|
|
95
|
+
if v.to_s.empty?
|
|
96
|
+
set_port(nil)
|
|
97
|
+
return
|
|
101
98
|
end
|
|
102
99
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
if host.nil? || host.empty? || scheme == "file"
|
|
101
|
+
raise InvalidURIError, "cannot set port when host is nil or scheme is file"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
parse_result = URI::DEFAULT_PARSER.split("#{v}:", url: self, state_override: :port_state)
|
|
105
|
+
set_port(parse_result[3])
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
def
|
|
109
|
-
return
|
|
108
|
+
def path=(v)
|
|
109
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
110
|
+
return if v.nil?
|
|
110
111
|
|
|
111
112
|
if @opaque
|
|
112
113
|
raise InvalidURIError, "path conflicts with opaque"
|
|
113
114
|
end
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
parse_result = URI::DEFAULT_PARSER.split(v.to_s, url: self, state_override: :path_start_state)
|
|
117
|
+
set_path(parse_result[5])
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def userinfo=(userinfo)
|
|
121
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
122
|
+
|
|
123
|
+
user, password = split_userinfo(userinfo)
|
|
124
|
+
self.user = user
|
|
125
|
+
self.password = password
|
|
118
126
|
end
|
|
119
127
|
|
|
120
128
|
def check_opaque(v)
|
|
129
|
+
return super unless URI::DEFAULT_PARSER.is_a?(URI::WhatwgParser)
|
|
121
130
|
return v unless v
|
|
122
131
|
|
|
123
132
|
if @host || @port || @user || @path
|
|
@@ -11,7 +11,7 @@ class URI::WhatwgParser
|
|
|
11
11
|
FORBIDDEN_DOMAIN_CODE_POINT = FORBIDDEN_HOST_CODE_POINT + C0_CONTROL_PERCENT_ENCODE_SET + ["%", "\x7f"]
|
|
12
12
|
|
|
13
13
|
def parse(input, opaque = false) # :nodoc:
|
|
14
|
-
return if input&.empty?
|
|
14
|
+
return "" if input&.empty?
|
|
15
15
|
|
|
16
16
|
if input.start_with?("[")
|
|
17
17
|
raise ParseError, "invalid IPv6 format" unless input.end_with?("]")
|
|
@@ -198,8 +198,6 @@ class URI::WhatwgParser
|
|
|
198
198
|
str.gsub(/%[0-9A-Fa-f]{2}/) do |m|
|
|
199
199
|
m[1..2].to_i(16).chr
|
|
200
200
|
end
|
|
201
|
-
rescue ArgumentError
|
|
202
|
-
raise ParseError, "including invalid value in host"
|
|
203
201
|
end
|
|
204
202
|
|
|
205
203
|
def ends_in_number?(domain)
|
data/lib/uri/whatwg_parser.rb
CHANGED
|
@@ -24,7 +24,7 @@ module URI
|
|
|
24
24
|
|
|
25
25
|
WINDOWS_DRIVE_LETTER = Regexp.new("\\A([a-zA-Z][:|])\\z")
|
|
26
26
|
NORMALIZED_WINDOWS_DRIVE_LETTER = Regexp.new("\\A([a-zA-Z][:])\\z")
|
|
27
|
-
|
|
27
|
+
STARTS_WITH_WINDOWS_DRIVE_LETTER = Regexp.new("\\A([a-zA-Z][:|])(?:[/\\?#])?\\z")
|
|
28
28
|
|
|
29
29
|
def initialize
|
|
30
30
|
reset
|
|
@@ -35,41 +35,57 @@ module URI
|
|
|
35
35
|
{}
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
def parse(
|
|
39
|
-
URI.for(*self.split(
|
|
38
|
+
def parse(input, base: nil, encoding: Encoding::UTF_8, url: nil, state_override: nil) # :nodoc:
|
|
39
|
+
URI.for(*self.split(input, base: base, encoding: encoding, url: url, state_override: state_override))
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
def split(
|
|
42
|
+
def split(input, base: nil, encoding: Encoding::UTF_8, url: nil, state_override: nil) # :nodoc:
|
|
43
43
|
reset
|
|
44
44
|
@base = nil
|
|
45
45
|
if base != nil
|
|
46
|
-
ary = split(base, nil, encoding)
|
|
46
|
+
ary = split(base, base: nil, encoding: encoding)
|
|
47
47
|
@base = { scheme: ary[0], userinfo: ary[1], host: ary[2], port: ary[3], registry: ary[4], path: ary[5], opaque: ary[6], query: ary[7], fragment: ary[8]}
|
|
48
48
|
@base_paths = @paths
|
|
49
49
|
reset
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
if url
|
|
53
|
+
raise ArgumentError, "bad argument (expected URI object)" unless url.is_a?(URI::Generic)
|
|
54
|
+
@parse_result.merge!(url.component.zip(url.send(:component_ary)).to_h)
|
|
55
|
+
@parse_result[:path] = nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if state_override
|
|
59
|
+
@state = state_override.to_sym
|
|
60
|
+
@state_override = @state
|
|
61
|
+
raise ArgumentError, "state override is invalid" if !state_override.to_s.end_with?("_state") || !respond_to?(@state_override, private: true)
|
|
62
|
+
else
|
|
63
|
+
raise ParseError, "uri can't be empty" if (input.nil? || input.empty?) && @base.nil?
|
|
64
|
+
end
|
|
65
|
+
|
|
52
66
|
@encoding = encoding
|
|
53
|
-
@
|
|
54
|
-
@uri.sub!(/\A[\u0000-\u0020]*/, "")
|
|
55
|
-
@uri.sub!(/[\u0000-\u0020]*\z/, "")
|
|
56
|
-
@uri.delete!("\t")
|
|
57
|
-
@uri.delete!("\n")
|
|
58
|
-
@uri.delete!("\r")
|
|
67
|
+
@input = input.dup
|
|
59
68
|
|
|
60
|
-
|
|
69
|
+
unless url
|
|
70
|
+
@input.sub!(/\A[\u0000-\u0020]*/, "")
|
|
71
|
+
@input.sub!(/[\u0000-\u0020]*\z/, "")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
@input.delete!("\t")
|
|
75
|
+
@input.delete!("\n")
|
|
76
|
+
@input.delete!("\r")
|
|
61
77
|
|
|
62
78
|
@pos = 0
|
|
63
79
|
|
|
64
|
-
while @pos <= @
|
|
65
|
-
c = @
|
|
66
|
-
send(@state, c)
|
|
80
|
+
while @pos <= @input.length
|
|
81
|
+
c = @input[@pos]
|
|
82
|
+
ret = send(@state, c)
|
|
83
|
+
break if ret == :terminate
|
|
67
84
|
@pos += 1
|
|
68
85
|
end
|
|
69
86
|
|
|
70
87
|
@parse_result[:userinfo] = [@username, @password].compact.reject(&:empty?).join(":")
|
|
71
88
|
@parse_result[:path] = "/#{@paths.join("/")}" if @paths && !@paths.empty?
|
|
72
|
-
|
|
73
89
|
@parse_result.values
|
|
74
90
|
end
|
|
75
91
|
|
|
@@ -77,14 +93,20 @@ module URI
|
|
|
77
93
|
return parse(uris[0]) if uris.size == 1
|
|
78
94
|
|
|
79
95
|
base, input = uris.shift(2)
|
|
80
|
-
uri = parse(input.to_s, base.to_s)
|
|
96
|
+
uri = parse(input.to_s, base: base.to_s)
|
|
81
97
|
uris.each do |input|
|
|
82
|
-
uri = parse(input.to_s, uri.to_s)
|
|
98
|
+
uri = parse(input.to_s, base: uri.to_s)
|
|
83
99
|
end
|
|
84
100
|
|
|
85
101
|
uri
|
|
86
102
|
end
|
|
87
103
|
|
|
104
|
+
def encode_userinfo(str)
|
|
105
|
+
str.chars.map do |char|
|
|
106
|
+
percent_encode(char, USERINFO_PERCENT_ENCODE_SET)
|
|
107
|
+
end.join
|
|
108
|
+
end
|
|
109
|
+
|
|
88
110
|
private
|
|
89
111
|
|
|
90
112
|
def reset
|
|
@@ -96,7 +118,7 @@ module URI
|
|
|
96
118
|
@username = nil
|
|
97
119
|
@password = nil
|
|
98
120
|
@parse_result = { scheme: nil, userinfo: nil, host: nil, port: nil, registry: nil, path: nil, opaque: nil, query: nil, fragment: nil }
|
|
99
|
-
@
|
|
121
|
+
@state_override = nil
|
|
100
122
|
@state = :scheme_start_state
|
|
101
123
|
end
|
|
102
124
|
|
|
@@ -104,9 +126,11 @@ module URI
|
|
|
104
126
|
if ascii_alpha?(c)
|
|
105
127
|
@buffer << c.downcase
|
|
106
128
|
@state = :scheme_state
|
|
107
|
-
|
|
129
|
+
elsif @state_override.nil?
|
|
108
130
|
@pos -= 1
|
|
109
131
|
@state = :no_scheme_state
|
|
132
|
+
else
|
|
133
|
+
raise ParseError, "scheme is invalid value"
|
|
110
134
|
end
|
|
111
135
|
end
|
|
112
136
|
|
|
@@ -114,7 +138,24 @@ module URI
|
|
|
114
138
|
if ascii_alphanumerica?(c) || ["+", "-", "."].include?(c)
|
|
115
139
|
@buffer << c.downcase
|
|
116
140
|
elsif c == ":"
|
|
141
|
+
if @state_override
|
|
142
|
+
if (special_url? && !special_url?(@buffer)) ||
|
|
143
|
+
(!special_url? && special_url?(@buffer)) ||
|
|
144
|
+
((includes_credentials? || !@parse_result[:port].nil?) && @buffer == "file") ||
|
|
145
|
+
(@parse_result[:scheme] == "file" && @parse_result[:host]&.empty?)
|
|
146
|
+
return :terminate
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
117
150
|
@parse_result[:scheme] = @buffer
|
|
151
|
+
|
|
152
|
+
if @state_override
|
|
153
|
+
if SPECIAL_SCHEME.value?(@parse_result[:port].to_i)
|
|
154
|
+
@parse_result[:port] = nil
|
|
155
|
+
end
|
|
156
|
+
return :terminate
|
|
157
|
+
end
|
|
158
|
+
|
|
118
159
|
@buffer = +""
|
|
119
160
|
|
|
120
161
|
if @parse_result[:scheme] == "file"
|
|
@@ -130,10 +171,12 @@ module URI
|
|
|
130
171
|
@parse_result[:opaque] = ""
|
|
131
172
|
@state = :opaque_path_state
|
|
132
173
|
end
|
|
133
|
-
|
|
174
|
+
elsif @state_override.nil?
|
|
134
175
|
@buffer.clear
|
|
135
176
|
@pos = -1
|
|
136
177
|
@state = :no_scheme_state
|
|
178
|
+
else
|
|
179
|
+
raise ParseError, "parsing scheme failed"
|
|
137
180
|
end
|
|
138
181
|
end
|
|
139
182
|
|
|
@@ -265,8 +308,12 @@ module URI
|
|
|
265
308
|
end
|
|
266
309
|
|
|
267
310
|
def host_state(c)
|
|
268
|
-
if
|
|
311
|
+
if @state_override && @parse_result[:scheme] == "file"
|
|
312
|
+
@pos -= 1
|
|
313
|
+
@state = :file_host_state
|
|
314
|
+
elsif c == ":" && !@inside_brackets
|
|
269
315
|
raise ParseError, "host is missing" if @buffer.empty?
|
|
316
|
+
raise ParseError, "invalid host" if @state_override && @state_override == :hostname_state
|
|
270
317
|
|
|
271
318
|
@parse_result[:host] = @host_parser.parse(@buffer, !special_url?)
|
|
272
319
|
@buffer.clear
|
|
@@ -275,10 +322,13 @@ module URI
|
|
|
275
322
|
@pos -= 1
|
|
276
323
|
if special_url? && @buffer.empty?
|
|
277
324
|
raise ParseError, "host is missing"
|
|
325
|
+
elsif @state_override && @buffer.empty? && (includes_credentials? || !@parse_result[:port].nil?)
|
|
326
|
+
raise ParseError, "invalid host"
|
|
278
327
|
else
|
|
279
328
|
@parse_result[:host] = @host_parser.parse(@buffer, !special_url?)
|
|
280
329
|
@buffer.clear
|
|
281
330
|
@state = :path_start_state
|
|
331
|
+
return :terminate if @state_override
|
|
282
332
|
end
|
|
283
333
|
else
|
|
284
334
|
@inside_brackets = true if c == "["
|
|
@@ -290,19 +340,21 @@ module URI
|
|
|
290
340
|
def port_state(c)
|
|
291
341
|
if ascii_digit?(c)
|
|
292
342
|
@buffer << c
|
|
293
|
-
elsif c.nil? || ["/", "?", "#"].include?(c) || (special_url? && c == "\\")
|
|
343
|
+
elsif c.nil? || ["/", "?", "#"].include?(c) || (special_url? && c == "\\") || @state_override
|
|
294
344
|
unless @buffer.empty?
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
@parse_result[:port] =
|
|
299
|
-
|
|
300
|
-
|
|
345
|
+
port = Integer(@buffer, 10)
|
|
346
|
+
raise ParseError, "port is invalid value" if port < 0 || port > 65535
|
|
347
|
+
if SPECIAL_SCHEME[@parse_result[:scheme]] == port
|
|
348
|
+
@parse_result[:port] = nil
|
|
349
|
+
else
|
|
350
|
+
@parse_result[:port] = port
|
|
301
351
|
end
|
|
302
352
|
|
|
303
353
|
@buffer.clear
|
|
354
|
+
return :terminate if @state_override
|
|
304
355
|
end
|
|
305
356
|
|
|
357
|
+
raise ParseError, "port is invalid value" if @state_override
|
|
306
358
|
@state = :path_start_state
|
|
307
359
|
@pos -= 1
|
|
308
360
|
else
|
|
@@ -348,7 +400,10 @@ module URI
|
|
|
348
400
|
if !@base.nil? && @base[:scheme] == "file"
|
|
349
401
|
@parse_result[:host] = @base[:host]
|
|
350
402
|
if !starts_with_windows_drive_letter?(rest) && @base_paths && normalized_windows_drive_letter?(@base_paths[0])
|
|
351
|
-
@paths
|
|
403
|
+
if @paths.nil?
|
|
404
|
+
@paths ||= []
|
|
405
|
+
@paths[0] = @base_paths[0]
|
|
406
|
+
end
|
|
352
407
|
end
|
|
353
408
|
end
|
|
354
409
|
@state = :path_state
|
|
@@ -360,49 +415,53 @@ module URI
|
|
|
360
415
|
if c.nil? || c == "/" || c == "\\" || c == "?" || c == "#"
|
|
361
416
|
@pos -= 1
|
|
362
417
|
|
|
363
|
-
if windows_drive_letter?(@buffer)
|
|
418
|
+
if !@state_override && windows_drive_letter?(@buffer)
|
|
364
419
|
@state = :path_state
|
|
365
420
|
elsif @buffer.empty?
|
|
366
421
|
@parse_result[:host] = nil
|
|
422
|
+
return :terminate if @state_override
|
|
367
423
|
@state = :path_start_state
|
|
368
424
|
else
|
|
369
425
|
host = @host_parser.parse(@buffer, !special_url?)
|
|
370
|
-
if host
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
426
|
+
host = "" if host == "localhost"
|
|
427
|
+
@parse_result[:host] = host
|
|
428
|
+
return :terminate if @state_override
|
|
374
429
|
@buffer.clear
|
|
375
430
|
@state = :path_start_state
|
|
376
431
|
end
|
|
432
|
+
else
|
|
433
|
+
@buffer << c unless c.nil?
|
|
377
434
|
end
|
|
378
|
-
|
|
379
|
-
@buffer << c unless c.nil?
|
|
380
435
|
end
|
|
381
436
|
|
|
382
437
|
def path_start_state(c)
|
|
383
438
|
if special_url?
|
|
384
439
|
@pos -= 1 if c != "/" && c != "\\"
|
|
385
440
|
@state = :path_state
|
|
386
|
-
elsif c == "?"
|
|
441
|
+
elsif !@state_override && c == "?"
|
|
387
442
|
@state = :query_state
|
|
388
|
-
elsif c == "#"
|
|
443
|
+
elsif !@state_override && c == "#"
|
|
389
444
|
@state = :fragment_state
|
|
390
445
|
elsif c != nil
|
|
391
446
|
@pos -= 1 if c != "/"
|
|
392
447
|
@state = :path_state
|
|
448
|
+
elsif @state_override && @parse_result[:host].nil?
|
|
449
|
+
@paths ||= []
|
|
450
|
+
@paths << ""
|
|
393
451
|
end
|
|
394
452
|
end
|
|
395
453
|
|
|
396
454
|
def path_state(c)
|
|
397
455
|
@paths ||= []
|
|
398
456
|
|
|
399
|
-
if (c.nil? || c == "/") || (special_url? && c == "
|
|
457
|
+
if (c.nil? || c == "/") || (special_url? && c == "\\") || (!@state_override && (c == "?" || c == "#"))
|
|
400
458
|
if double_dot_path_segments?(@buffer)
|
|
401
459
|
shorten_url_path
|
|
402
|
-
|
|
460
|
+
|
|
461
|
+
if c != "/" && !(special_url? && c == "\\")
|
|
403
462
|
@paths << ""
|
|
404
463
|
end
|
|
405
|
-
elsif single_dot_path_segments?(@buffer) &&
|
|
464
|
+
elsif single_dot_path_segments?(@buffer) && c != "/" && !((special_url? && c == "\\"))
|
|
406
465
|
@paths << ""
|
|
407
466
|
elsif !single_dot_path_segments?(@buffer)
|
|
408
467
|
if @parse_result[:scheme] == "file" && @paths.empty? && windows_drive_letter?(@buffer)
|
|
@@ -449,7 +508,7 @@ module URI
|
|
|
449
508
|
@encoding = Encoding::UTF_8
|
|
450
509
|
end
|
|
451
510
|
|
|
452
|
-
if c.nil? || c == "#"
|
|
511
|
+
if c.nil? || (!@state_override && c == "#")
|
|
453
512
|
query_percent_encode_set = special_url? ? SPECIAL_QUERY_PERCENT_ENCODE_SET : QUERY_PERCENT_ENCODE_SET
|
|
454
513
|
@parse_result[:query] = @buffer.chars.map { |c| percent_encode(c, query_percent_encode_set, @encoding) }.join
|
|
455
514
|
@buffer.clear
|
|
@@ -469,15 +528,15 @@ module URI
|
|
|
469
528
|
end
|
|
470
529
|
|
|
471
530
|
def starts_with_windows_drive_letter?(str)
|
|
472
|
-
|
|
531
|
+
STARTS_WITH_WINDOWS_DRIVE_LETTER.match?(str)
|
|
473
532
|
end
|
|
474
533
|
|
|
475
534
|
def normalized_windows_drive_letter?(str)
|
|
476
535
|
NORMALIZED_WINDOWS_DRIVE_LETTER.match?(str)
|
|
477
536
|
end
|
|
478
537
|
|
|
479
|
-
def special_url?
|
|
480
|
-
SPECIAL_SCHEME.key?(
|
|
538
|
+
def special_url?(str = @parse_result[:scheme])
|
|
539
|
+
SPECIAL_SCHEME.key?(str)
|
|
481
540
|
end
|
|
482
541
|
|
|
483
542
|
def single_dot_path_segments?(c)
|
|
@@ -490,13 +549,16 @@ module URI
|
|
|
490
549
|
|
|
491
550
|
def shorten_url_path
|
|
492
551
|
return if @paths.nil?
|
|
493
|
-
|
|
494
|
-
return true if @parse_result[:scheme] == "file" && @paths.length == 1 && normalized_windows_drive_letter?(@paths.first)
|
|
552
|
+
return if @parse_result[:scheme] == "file" && @paths.length == 1 && normalized_windows_drive_letter?(@paths.first)
|
|
495
553
|
@paths.pop
|
|
496
554
|
end
|
|
497
555
|
|
|
556
|
+
def includes_credentials?
|
|
557
|
+
!@parse_result[:userinfo].nil? || (@username && !@username.empty?) || (@password && !@password.empty?)
|
|
558
|
+
end
|
|
559
|
+
|
|
498
560
|
def rest
|
|
499
|
-
@
|
|
561
|
+
@input[@pos+1..]
|
|
500
562
|
end
|
|
501
563
|
|
|
502
564
|
def convert_to_uri(uri)
|
|
@@ -510,8 +572,10 @@ module URI
|
|
|
510
572
|
end
|
|
511
573
|
end
|
|
512
574
|
end
|
|
575
|
+
|
|
576
|
+
WHATWG_PARSER = URI::WhatwgParser.new
|
|
513
577
|
end
|
|
514
578
|
|
|
515
579
|
URI.send(:remove_const, :DEFAULT_PARSER) if defined?(URI::DEFAULT_PARSER)
|
|
516
|
-
URI::DEFAULT_PARSER = URI::
|
|
580
|
+
URI::DEFAULT_PARSER = URI::WHATWG_PARSER
|
|
517
581
|
URI.parser = URI::DEFAULT_PARSER
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uri-whatwg_parser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yuji Yaginuma
|
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
88
|
version: '0'
|
|
89
89
|
requirements: []
|
|
90
|
-
rubygems_version:
|
|
90
|
+
rubygems_version: 4.0.3
|
|
91
91
|
specification_version: 4
|
|
92
92
|
summary: Ruby implementation of the WHATWG URL Living Standard
|
|
93
93
|
test_files: []
|