-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathURI.txt
348 lines (296 loc) · 11.7 KB
/
URI.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
*vital/Web/URI.txt* URI manipulation library
Maintainer: tyru <[email protected]>
==============================================================================
CONTENTS *Vital.Web.URI-contents*
INTRODUCTION |Vital.Web.URI-introduction|
INTERFACE |Vital.Web.URI-interface|
Functions |Vital.Web.URI-functions|
URI Object |Vital.Web.URI-URI|
PatternSet Object |Vital.Web.URI-PatternSet|
NOTES |Vital.Web.URI-notes|
TODO |Vital.Web.URI-todo|
REFERENCES |Vital.Web.URI-references|
==============================================================================
INTRODUCTION *Vital.Web.URI-introduction*
*Vital.Web.URI* is URI manipulation library.
==============================================================================
INTERFACE *Vital.Web.URI-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Web.URI-functions*
new({str} [, {default} [, {patternset}]]) *Vital.Web.URI.new()*
Returns a |Vital.Web.URI-URI| object constructed by {str}.
If {default} is given and {str} is invalid,
returns {default}.
Otherwise, throws an exception.
See |Vital.Web.URI-PatternSet| for {patternset}.
new_from_uri_like_string({str} [, {default} [, {patternset}]])
*Vital.Web.URI.new_from_uri_like_string()*
This is same as |Vital.Web.URI.new()|
except when {str} has no scheme.
then this function prepends the string "http://" to {str}.
new_from_seq_string({str} [, {default} [, {patternset}]])
*Vital.Web.URI.new_from_seq_string()*
This is same as |Vital.Web.URI.new()|, except
1. When {str} contains illegal trailing string,
then this function DOES NOT throw an exception.
2. Returns |List| of [{uri}, {origuri}, {rest}]
{uri}
|Vital.Web.URI-URI| object constructed by {str}.
{origuri}
Original string which was used for constructing {uri}.
{rest}
Rest of string after parsing {str}.
is_uri({str}) *Vital.Web.URI.is_uri()*
Returns non-zero value if {str} is URI.
Returns zero value otherwise.
>
let URI = vital#{plugin-name}#new().import('Web.URI')
let ERROR = []
let like_uri = (URI.is_uri(a:str, ERROR) isnot ERROR)
<
like_uri({str}) *Vital.Web.URI.like_uri()*
Returns non-zero value if {str} looks like URI.
Returns zero value otherwise.
This is the |Vital.Web.URI.new_from_uri_like_string()| version
of |Vital.Web.URI.is_uri()|.
(This uses |Vital.Web.URI.new_from_uri_like_string()|
instead of |Vital.Web.URI.new()|)
*Vital.Web.URI.new_default_pattern_set()*
new_default_pattern_set()
Creates a new |Vital.Web.URI-PatternSet| object.
*Vital.Web.URI.clone_pattern_set()*
clone_pattern_set({patternset})
Clones a |Vital.Web.URI-PatternSet| object.
encode({str} [, {char-enc}]) *Vital.Web.URI.encode()*
Encodes {str} to Percent-encoding string.
Converts {str} to {char-enc}(or "utf-8" when omitted) before encode.
When {char-enc} is an empty string, {str} is not converted.
decode({str} [, {char-enc}]) *Vital.Web.URI.decode()*
Decodes {str} that is encoded by Percent-encoding.
Converts result from {char-enc}(or "utf-8" when omitted) to 'encoding'
after decode.
When {char-enc} is an empty string, result is not converted.
Note that this function does not convert "+" to " ".
Because this function is based on percent-encoding in RFC3986.
http://tools.ietf.org/html/rfc3986#section-2.1
But "+" conversion is based on
application/x-www-form-urlencoded in RFC1866.
http://tools.ietf.org/html/rfc1866#section-8.2.1
------------------------------------------------------------------------------
URI OBJECT *Vital.Web.URI-URI* *Vital.Web.URI-object*
NOTE: See |Vital.Web.HTTP| for encoding/decoding functions.
* |Vital.Web.HTTP.encodeURI()|
* |Vital.Web.HTTP.encodeURIComponent()|
* |Vital.Web.HTTP.decodeURI()|
*Vital.Web.URI-URI.scheme()* *Vital.Web.URI-object.scheme()*
*Vital.Web.URI-URI.host()* *Vital.Web.URI-object.host()*
*Vital.Web.URI-URI.port()* *Vital.Web.URI-object.port()*
*Vital.Web.URI-URI.path()* *Vital.Web.URI-object.path()*
*Vital.Web.URI-URI.opaque()* *Vital.Web.URI-object.opaque()*
*Vital.Web.URI-URI.authority()* *Vital.Web.URI-object.authority()*
*Vital.Web.URI-URI.query()* *Vital.Web.URI-object.query()*
*Vital.Web.URI-URI.fragment()* *Vital.Web.URI-object.fragment()*
scheme([{str}])
userinfo([{str}])
host([{str}])
port([{str}])
path([{str}])
authority([{str}])
opaque([{str}])
query([{str}])
fragment([{str}])
If no arguments are given, returns each part value.
If {str} is given, sets {str} as each part value,
and returns the URI object itself.
NOTE: opaque(), authority() do not support {str} yet.
NOTE: port({str}) allows both Number and String for {str}.
to_iri([{char-enc}]) *Vital.Web.URI-object.to_iri()*
Same as |Vital.Web.URI-object.to_string()|,
but do URI-unescape for |Vital.Web.URI-object.path()| part.
Passes {char-enc} to |Vital.Web.URI.decode()| if specified.
to_string() *Vital.Web.URI-object.to_string()*
Returns URI representation of this object.
*Vital.Web.URI-URI.is_scheme()*
*Vital.Web.URI-URI.is_userinfo()*
*Vital.Web.URI-URI.is_host()*
*Vital.Web.URI-URI.is_port()*
*Vital.Web.URI-URI.is_path()*
*Vital.Web.URI-URI.is_query()*
*Vital.Web.URI-URI.is_fragment()*
is_scheme({str})
is_userinfo({str})
is_host({str})
is_port({str})
is_path({str})
is_query({str})
is_fragment({str})
Returns non-zero value if {str} has right syntax
for each component. Returns zero otherwise.
*Vital.Web.URI-URI.clone()*
clone()
This method clones a URI object itself. >
let s:URI = vital#{plugin-name}#new().import('Web.URI')
let uri = s:URI.new('http://example.com/')
let copyuri = uri.clone().relative('/a/b/c')
echo uri.to_string()
" => 'http://example.com/'
echo copyuri.to_string()
" => 'http://example.com/a/b/c'
<
*Vital.Web.URI-URI.relative()*
relative({reluri})
This method ...
* Calculates a URI from
base URI and relative URI({reluri}).
* Changes the URI object itself (destructive).
* Returns the URI object itself.
* Calls |Vital.Web.URI-URI.relative()| implicitly.
Example: >
let s:URI = vital#{plugin-name}#new().import('Web.URI')
let BASE_URI = 'http://example.com/foo/bar'
let RELATIVE_URI = '../baz'
echo s:URI.new(BASE_URI).relative(RELATIVE_URI).to_string()
" => 'http://example.com/baz'
let BASE_URI = 'http://example.com/foo/bar/'
let RELATIVE_URI = '../baz'
echo s:URI.new(BASE_URI).relative(RELATIVE_URI).to_string()
" => 'http://example.com/foo/baz'
<
*Vital.Web.URI-URI.canonicalize()*
canonicalize()
This method ...
* Canonicalizes the URI.
* Changes the URI object itself (destructive).
* Returns the URI object itself.
See Web.URI.* modules for supported schemes.
For example, the following four URIs
becomes equivalent URI (http://example.com/).
* http://example.com
* http://example.com/
* http://example.com:/
* http://example.com:80/
Example: >
let s:URI = vital#{plugin-name}#new().import('Web.URI')
echo s:URI.new('http://example.com:80/').to_string()
" => 'http://example.com/'
<
*Vital.Web.URI-URI.default_port()*
default_port()
This method returns the default port for current scheme.
(e.g.: 80 for "http" scheme)
See Web.URI.* modules for supported schemes.
------------------------------------------------------------------------------
PATTERNSET OBJECT *Vital.Web.URI-PatternSet*
PatternSet object is the set of patterns for URI syntax.
This object has each method for URI components based on RFC3986
and all components are fully customizable.
e.g.: scheme(), host(), path(), ...
Below is the example how to customize URI component definition.
This example allows more tolerant URI parsing.
(This example is from https://github.com/tyru/open-browser.vim/issues/72)
The default PatternSet is very strict
because it is completely RFC3986 based implementation.
(_default_ means the object which
|Vital.Web.URI.new_default_pattern_set()| returns)
According to RFC3986, URI allows
* ' (single quote)
* ( (left parenthesis)
* ) (right parenthesis)
but these characters often appears in ordinary text.
This code lets the parser ignore these characters. >
let s:LoosePatternSet = s:URI.new_default_pattern_set()
" Remove "'", "(", ")" from default sub_delims().
function! s:LoosePatternSet.sub_delims() abort
return '[!$&*+,;=]'
endfunction
" Ignore trailing string after URI.
let NONE = []
let ret = URI.new_from_seq_string(
\ 'http://example.com)', NONE, s:LoosePatternSet)
if ret isnot NONE
...
endif
<
get({component}) *Vital.Web.URI-PatternSet.get()*
Returns each component definition.
>
let s:PatternSet = s:URI.new_default_pattern_set()
echo s:PatternSet.get('scheme')
<
Listing all customizable components here (alphabetic order).
NOTE: DON'T call these methods directly.
These methods are used when defining customized PatternSet.
See how-to at |Vital.Web.URI-PatternSet|.
dec_octet() *Vital.Web.URI-PatternSet.dec_octet()*
fragment() *Vital.Web.URI-PatternSet.fragment()*
h16() *Vital.Web.URI-PatternSet.h16()*
hexdig() *Vital.Web.URI-PatternSet.hexdig()*
host() *Vital.Web.URI-PatternSet.host()*
ip_literal() *Vital.Web.URI-PatternSet.ip_literal()*
ipv4address() *Vital.Web.URI-PatternSet.ipv4address()*
ipv6address() *Vital.Web.URI-PatternSet.ipv6address()*
ipv_future() *Vital.Web.URI-PatternSet.ipv_future()*
ls32() *Vital.Web.URI-PatternSet.ls32()*
path() *Vital.Web.URI-PatternSet.path()*
path_abempty() *Vital.Web.URI-PatternSet.path_abempty()*
path_absolute() *Vital.Web.URI-PatternSet.path_absolute()*
path_noscheme() *Vital.Web.URI-PatternSet.path_noscheme()*
path_rootless() *Vital.Web.URI-PatternSet.path_rootless()*
pchar() *Vital.Web.URI-PatternSet.pchar()*
pct_encoded() *Vital.Web.URI-PatternSet.pct_encoded()*
port() *Vital.Web.URI-PatternSet.port()*
query() *Vital.Web.URI-PatternSet.query()*
reg_name() *Vital.Web.URI-PatternSet.reg_name()*
scheme() *Vital.Web.URI-PatternSet.scheme()*
segment() *Vital.Web.URI-PatternSet.segment()*
segment_nz() *Vital.Web.URI-PatternSet.segment_nz()*
segment_nz_nc() *Vital.Web.URI-PatternSet.segment_nz_nc()*
sub_delims() *Vital.Web.URI-PatternSet.sub_delims()*
unreserved() *Vital.Web.URI-PatternSet.unreserved()*
userinfo() *Vital.Web.URI-PatternSet.userinfo()*
==============================================================================
NOTES *Vital.Web.URI-notes*
Empty authority
-----------------
Empty authority is allowed for "file" scheme,
but not for almost schemes, for example, "http" scheme.
However, Web.URI does not concern about
authority handling for each scheme,
because it is just a parser library for URI.
If a user wants to raise an error for a such case,
needs to raise an error for him or herself.
==============================================================================
TODO *Vital.Web.URI-todo*
* Punycode (RFC3492)
* IRI support (RFC3987)
* |Vital.Web.URI-URI.opaque()| with an argument
* |Vital.Web.URI-URI.authority()| with an argument
* Perl's URI, URI::Find module
* `URI::eq()`
* `URI::query_form()`
* `URI::query_keywords()`
* `URI::ihost()`
* `URI::Find::find()`
* RFC 5890: IDNA (Internationalized Domain Names for Applications)
* A Label
* U Label
* NR-LDH Label
* `s:URI.to_string()` should recompose string by the algorithm
based on https://tools.ietf.org/html/rfc3986#section-5.3
* `s:URI.to_iri()`: Write tests
* `s:URI.to_iri()`: Write document
* URN Support
* urn:isbn
* urn:uuid
* urn:ietf:rfc
* urn:oid
==============================================================================
REFERENCES *Vital.Web.URI-references*
* URL: Living Standard
https://url.spec.whatwg.org/#informative
* RFC3986
http://tools.ietf.org/html/rfc3986
* RFC3986 Errata
https://www.rfc-editor.org/errata_search.php?rfc=3987
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl