uri-whatwg_parser 0.1.7 → 0.1.8
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 +1 -1
- data/lib/uri/whatwg_parser/generic.rb +121 -0
- data/lib/uri/whatwg_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4463680cf6d13f3daf3513549ebe358f7b45484888704bbefffcecbb1790b8c7
|
|
4
|
+
data.tar.gz: b5ec5b9ad687c53f71f2fa21bcb049215dfff6ecdcb8305594f569ba86c0b210
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ff5fd142e640d265e4d3bd11174e7658732430055d45cce16364bc783c85f7f642d3654d9621e2fa198d63f8e82959fa5d4588d611f6c3e3c3f2d46f382df9e
|
|
7
|
+
data.tar.gz: b389a5a39685d81ce3ade458b1d61746e9b0dca6e227b73658fe6c04910f20908a1669fd884c5e445bb401edc1db3915e21d15bdec8acf1b441c9c9b3e7e65d8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Ruby implementation of the [WHATWG URL Living Standard](https://url.spec.whatwg.org/).
|
|
4
4
|
|
|
5
|
-
The latest revision that this package implements of the standard is ([
|
|
5
|
+
The latest revision that this package implements of the standard is ([30 October 2025](https://url.spec.whatwg.org/commit-snapshots/52526653e848c5a56598c84aa4bc8ac9025fb66b/)).
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -3,10 +3,131 @@ require "uri/generic"
|
|
|
3
3
|
module URI
|
|
4
4
|
class WhatwgParser
|
|
5
5
|
module Generic
|
|
6
|
+
def initialize(scheme,
|
|
7
|
+
userinfo, host, port, registry,
|
|
8
|
+
path, opaque,
|
|
9
|
+
query,
|
|
10
|
+
fragment,
|
|
11
|
+
parser = DEFAULT_PARSER,
|
|
12
|
+
arg_check = false)
|
|
13
|
+
@scheme = nil
|
|
14
|
+
@user = nil
|
|
15
|
+
@password = nil
|
|
16
|
+
@host = nil
|
|
17
|
+
@port = nil
|
|
18
|
+
@path = nil
|
|
19
|
+
@query = nil
|
|
20
|
+
@opaque = nil
|
|
21
|
+
@fragment = nil
|
|
22
|
+
@parser = parser == DEFAULT_PARSER ? nil : parser
|
|
23
|
+
|
|
24
|
+
self.set_scheme(scheme)
|
|
25
|
+
self.set_host(host)
|
|
26
|
+
self.set_port(port)
|
|
27
|
+
self.set_userinfo(userinfo)
|
|
28
|
+
self.set_path(path)
|
|
29
|
+
self.query = query
|
|
30
|
+
self.set_opaque(opaque)
|
|
31
|
+
self.fragment=(fragment)
|
|
32
|
+
|
|
33
|
+
self.set_path("") if !@path && !@opaque
|
|
34
|
+
DEFAULT_PARSER.parse(to_s) if arg_check
|
|
35
|
+
|
|
36
|
+
if registry
|
|
37
|
+
raise InvalidURIError,
|
|
38
|
+
"the scheme #{@scheme} does not accept registry part: #{registry} (or bad hostname?)"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
@scheme&.freeze
|
|
42
|
+
self.set_port(self.default_port) if self.default_port && !@port
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
6
46
|
def merge(oth)
|
|
7
47
|
URI::DEFAULT_PARSER.join(self.to_s, oth.to_s)
|
|
8
48
|
end
|
|
9
49
|
alias + merge
|
|
50
|
+
|
|
51
|
+
def check_scheme(v)
|
|
52
|
+
self.set_scheme(v)
|
|
53
|
+
DEFAULT_PARSER.parse(to_s)
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def check_user(v)
|
|
58
|
+
if @opaque
|
|
59
|
+
raise InvalidURIError, "cannot set user with opaque"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
return v unless v
|
|
63
|
+
|
|
64
|
+
self.set_user(v)
|
|
65
|
+
DEFAULT_PARSER.parse(to_s)
|
|
66
|
+
true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def check_password(v, user = @user)
|
|
70
|
+
if @opaque
|
|
71
|
+
raise InvalidURIError, "cannot set password with opaque"
|
|
72
|
+
end
|
|
73
|
+
return v unless v
|
|
74
|
+
|
|
75
|
+
if !user
|
|
76
|
+
raise InvalidURIError, "password component depends user component"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
self.set_password(v)
|
|
80
|
+
DEFAULT_PARSER.parse(to_s)
|
|
81
|
+
true
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def check_host(v)
|
|
85
|
+
return v unless v
|
|
86
|
+
|
|
87
|
+
if @opaque
|
|
88
|
+
raise InvalidURIError, "cannot set host with registry or opaque"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
self.set_host(v)
|
|
92
|
+
DEFAULT_PARSER.parse(to_s)
|
|
93
|
+
true
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def check_port(v)
|
|
97
|
+
return v unless v
|
|
98
|
+
|
|
99
|
+
if @opaque
|
|
100
|
+
raise InvalidURIError, "cannot set port with registry or opaque"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
self.set_port(v)
|
|
104
|
+
DEFAULT_PARSER.parse(to_s)
|
|
105
|
+
true
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def check_path(v)
|
|
109
|
+
return v unless v
|
|
110
|
+
|
|
111
|
+
if @opaque
|
|
112
|
+
raise InvalidURIError, "path conflicts with opaque"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
self.set_path(v)
|
|
116
|
+
DEFAULT_PARSER.parse(to_s)
|
|
117
|
+
true
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def check_opaque(v)
|
|
121
|
+
return v unless v
|
|
122
|
+
|
|
123
|
+
if @host || @port || @user || @path
|
|
124
|
+
raise InvalidURIError, "cannot set opaque with host, port, userinfo or path"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
self.set_opaque(v)
|
|
128
|
+
DEFAULT_PARSER.parse(to_s)
|
|
129
|
+
true
|
|
130
|
+
end
|
|
10
131
|
end
|
|
11
132
|
end
|
|
12
133
|
end
|