bare-url 0.3.8 → 1.0.1
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.
- package/CMakeLists.txt +27 -0
- package/binding.c +111 -0
- package/binding.js +1 -0
- package/index.js +74 -90
- package/lib/errors.js +0 -105
- package/package.json +14 -3
- package/prebuilds/darwin-arm64/bare-url.bare +0 -0
- package/prebuilds/darwin-x64/bare-url.bare +0 -0
- package/prebuilds/linux-arm64/bare-url.bare +0 -0
- package/prebuilds/linux-x64/bare-url.bare +0 -0
- package/prebuilds/win32-x64/bare-url.bare +0 -0
- package/vendor/liburl/CMakeLists.txt +79 -0
- package/vendor/liburl/LICENSE +201 -0
- package/vendor/liburl/README.md +27 -0
- package/vendor/liburl/include/url.h +107 -0
- package/vendor/liburl/src/character-set.h +41 -0
- package/vendor/liburl/src/idna.h +14 -0
- package/vendor/liburl/src/infra.h +141 -0
- package/vendor/liburl/src/parse.h +1390 -0
- package/vendor/liburl/src/percent-encode.h +567 -0
- package/vendor/liburl/src/punycode.h +21 -0
- package/vendor/liburl/src/serialize.h +91 -0
- package/vendor/liburl/src/type.h +61 -0
- package/vendor/liburl/src/url.c +81 -0
- package/vendor/libutf/CMakeLists.txt +76 -0
- package/vendor/libutf/LICENSE +201 -0
- package/vendor/libutf/README.md +11 -0
- package/vendor/libutf/include/utf/endianness.h +54 -0
- package/vendor/libutf/include/utf/string.h +759 -0
- package/vendor/libutf/include/utf.h +45 -0
- package/vendor/libutf/src/endianness.c +19 -0
- package/vendor/libutf/src/utf16/utf8-convert.c +77 -0
- package/vendor/libutf/src/utf16/utf8-length.c +45 -0
- package/vendor/libutf/src/utf16/validate.c +53 -0
- package/vendor/libutf/src/utf8/string.c +148 -0
- package/vendor/libutf/src/utf8/utf16-convert.c +90 -0
- package/vendor/libutf/src/utf8/utf16-length.c +39 -0
- package/vendor/libutf/src/utf8/validate.c +107 -0
- package/lib/constants.js +0 -25
- package/lib/infra.js +0 -39
- package/lib/parse.js +0 -941
- package/lib/serialize.js +0 -98
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.25)
|
|
2
|
+
|
|
3
|
+
project(bare_url C)
|
|
4
|
+
|
|
5
|
+
include(bare)
|
|
6
|
+
|
|
7
|
+
if(NOT TARGET utf)
|
|
8
|
+
add_subdirectory(vendor/libutf EXCLUDE_FROM_ALL)
|
|
9
|
+
endif()
|
|
10
|
+
|
|
11
|
+
if(NOT TARGET url)
|
|
12
|
+
add_subdirectory(vendor/liburl EXCLUDE_FROM_ALL)
|
|
13
|
+
endif()
|
|
14
|
+
|
|
15
|
+
add_bare_module(bare_url)
|
|
16
|
+
|
|
17
|
+
target_sources(
|
|
18
|
+
bare_url
|
|
19
|
+
PRIVATE
|
|
20
|
+
binding.c
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
target_link_libraries(
|
|
24
|
+
bare_url
|
|
25
|
+
PUBLIC
|
|
26
|
+
url_static
|
|
27
|
+
)
|
package/binding.c
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
#include <bare.h>
|
|
3
|
+
#include <js.h>
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
#include <url.h>
|
|
8
|
+
#include <utf.h>
|
|
9
|
+
#include <utf/string.h>
|
|
10
|
+
|
|
11
|
+
static js_value_t *
|
|
12
|
+
bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
13
|
+
int err;
|
|
14
|
+
|
|
15
|
+
size_t argc = 3;
|
|
16
|
+
js_value_t *argv[3];
|
|
17
|
+
|
|
18
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
19
|
+
assert(err == 0);
|
|
20
|
+
|
|
21
|
+
assert(argc == 3);
|
|
22
|
+
|
|
23
|
+
bool has_base;
|
|
24
|
+
err = js_is_string(env, argv[1], &has_base);
|
|
25
|
+
assert(err == 0);
|
|
26
|
+
|
|
27
|
+
url_t base;
|
|
28
|
+
url_init(&base);
|
|
29
|
+
|
|
30
|
+
if (has_base) {
|
|
31
|
+
size_t len;
|
|
32
|
+
err = js_get_value_string_utf8(env, argv[1], NULL, 0, &len);
|
|
33
|
+
assert(err == 0);
|
|
34
|
+
|
|
35
|
+
utf8_t *input = malloc(len);
|
|
36
|
+
err = js_get_value_string_utf8(env, argv[1], input, len, NULL);
|
|
37
|
+
assert(err == 0);
|
|
38
|
+
|
|
39
|
+
err = url_parse(&base, input, len, NULL);
|
|
40
|
+
if (err < 0) {
|
|
41
|
+
free(input);
|
|
42
|
+
|
|
43
|
+
url_destroy(&base);
|
|
44
|
+
|
|
45
|
+
js_throw_error(env, NULL, "Invalid base URL");
|
|
46
|
+
|
|
47
|
+
return NULL;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
free(input);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
size_t len;
|
|
54
|
+
err = js_get_value_string_utf8(env, argv[0], NULL, 0, &len);
|
|
55
|
+
assert(err == 0);
|
|
56
|
+
|
|
57
|
+
utf8_t *input = malloc(len);
|
|
58
|
+
err = js_get_value_string_utf8(env, argv[0], input, len, NULL);
|
|
59
|
+
assert(err == 0);
|
|
60
|
+
|
|
61
|
+
uint32_t *components;
|
|
62
|
+
err = js_get_typedarray_info(env, argv[2], NULL, (void **) &components, NULL, NULL, NULL);
|
|
63
|
+
assert(err == 0);
|
|
64
|
+
|
|
65
|
+
js_value_t *handle;
|
|
66
|
+
|
|
67
|
+
url_t url;
|
|
68
|
+
url_init(&url);
|
|
69
|
+
|
|
70
|
+
err = url_parse(&url, input, len, has_base ? &base : NULL);
|
|
71
|
+
if (err < 0) {
|
|
72
|
+
free(input);
|
|
73
|
+
|
|
74
|
+
url_destroy(&base);
|
|
75
|
+
url_destroy(&url);
|
|
76
|
+
|
|
77
|
+
js_throw_error(env, NULL, "Invalid URL");
|
|
78
|
+
|
|
79
|
+
return NULL;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
free(input);
|
|
83
|
+
|
|
84
|
+
js_value_t *href;
|
|
85
|
+
err = js_create_string_utf8(env, url.href.data, url.href.len, &href);
|
|
86
|
+
assert(err == 0);
|
|
87
|
+
|
|
88
|
+
memcpy(components, &url.components, sizeof(url.components));
|
|
89
|
+
|
|
90
|
+
url_destroy(&url);
|
|
91
|
+
|
|
92
|
+
return href;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static js_value_t *
|
|
96
|
+
init (js_env_t *env, js_value_t *exports) {
|
|
97
|
+
int err;
|
|
98
|
+
|
|
99
|
+
{
|
|
100
|
+
js_value_t *fn;
|
|
101
|
+
err = js_create_function(env, "parse", -1, bare_url_parse, NULL, &fn);
|
|
102
|
+
assert(err == 0);
|
|
103
|
+
|
|
104
|
+
err = js_set_named_property(env, exports, "parse", fn);
|
|
105
|
+
assert(err == 0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return exports;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
BARE_MODULE(bare_url, init)
|
package/binding.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require.addon()
|
package/index.js
CHANGED
|
@@ -1,187 +1,140 @@
|
|
|
1
1
|
const path = require('bare-path')
|
|
2
2
|
const os = require('bare-os')
|
|
3
|
-
const
|
|
3
|
+
const safetyCatch = require('safety-catch')
|
|
4
|
+
const binding = require('./binding')
|
|
4
5
|
const errors = require('./lib/errors')
|
|
5
|
-
const parse = require('./lib/parse')
|
|
6
|
-
const serialize = require('./lib/serialize')
|
|
7
6
|
|
|
8
7
|
const URL = exports.URL = class URL {
|
|
9
8
|
constructor (href, base) {
|
|
10
|
-
if (typeof
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} catch (err) {
|
|
14
|
-
err.message = 'Invalid base URL'
|
|
15
|
-
throw err
|
|
16
|
-
}
|
|
17
|
-
}
|
|
9
|
+
if (typeof href !== 'string') throw errors.INVALID_URL()
|
|
10
|
+
|
|
11
|
+
if (base && typeof base !== 'string') base = base.href
|
|
18
12
|
|
|
19
|
-
this.
|
|
13
|
+
this._components = new Uint32Array(8)
|
|
14
|
+
|
|
15
|
+
this._parse(href, base)
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
// https://url.spec.whatwg.org/#dom-url-href
|
|
23
19
|
|
|
24
20
|
get href () {
|
|
25
|
-
return
|
|
21
|
+
return this._href
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
set href (value) {
|
|
29
|
-
this.
|
|
25
|
+
this._update(value)
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
// https://url.spec.whatwg.org/#dom-url-protocol
|
|
33
29
|
|
|
34
30
|
get protocol () {
|
|
35
|
-
return this.
|
|
31
|
+
return this._slice(0, this._components[0]) + ':'
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
set protocol (value) {
|
|
39
|
-
|
|
35
|
+
this._update(this._replace(value.replace(/:+$/, ''), 0, this._components[0]))
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
// https://url.spec.whatwg.org/#dom-url-username
|
|
43
39
|
|
|
44
40
|
get username () {
|
|
45
|
-
return this.
|
|
41
|
+
return this._slice(this._components[0] + 3 /* :// */, this._components[1])
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
set username (value) {
|
|
49
|
-
if (this
|
|
45
|
+
if (cannotHaveCredentialsOrPort(this)) {
|
|
50
46
|
return
|
|
51
47
|
}
|
|
52
48
|
|
|
53
|
-
this.
|
|
49
|
+
if (this.username === '') value += '@'
|
|
50
|
+
|
|
51
|
+
this._update(this._replace(value, this._components[0] + 3 /* :// */, this._components[1]))
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
// https://url.spec.whatwg.org/#dom-url-password
|
|
57
55
|
|
|
58
56
|
get password () {
|
|
59
|
-
return this.
|
|
57
|
+
return this._href.slice(this._components[1] + 1 /* : */, this._components[2] - 1 /* @ */)
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
set password (value) {
|
|
63
|
-
if (this
|
|
61
|
+
if (cannotHaveCredentialsOrPort(this)) {
|
|
64
62
|
return
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
this.
|
|
65
|
+
let start = this._components[1] + 1 /* : */
|
|
66
|
+
let end = this._components[2] - 1 /* @ */
|
|
67
|
+
|
|
68
|
+
if (this.password === '') {
|
|
69
|
+
value = ':' + value
|
|
70
|
+
start--
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (this.username === '') {
|
|
74
|
+
value += '@'
|
|
75
|
+
end++
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this._update(this._replace(value, start, end))
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
// https://url.spec.whatwg.org/#dom-url-host
|
|
71
82
|
|
|
72
83
|
get host () {
|
|
73
|
-
|
|
74
|
-
if (this._url.port === null) return serialize.host(this._url.host)
|
|
75
|
-
|
|
76
|
-
return serialize.host(this._url.host) + ':' + this._url.port.toString(10)
|
|
84
|
+
return this._slice(this._components[2], this._components[5])
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
set host (value) {
|
|
80
|
-
if (typeof this._url.path === 'string') return
|
|
81
|
-
|
|
82
|
-
parse(value, null, this._url, constants.STATE_HOST)
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
// https://url.spec.whatwg.org/#dom-url-hostname
|
|
86
91
|
|
|
87
92
|
get hostname () {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return serialize.host(this._url.host)
|
|
93
|
+
return this._slice(this._components[2], this._components[3])
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
set hostname (value) {
|
|
94
|
-
if (typeof this._url.path === 'string') return
|
|
95
|
-
|
|
96
|
-
parse(value, null, this._url, constants.STATE_HOSTNAME)
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// https://url.spec.whatwg.org/#dom-url-port
|
|
100
100
|
|
|
101
101
|
get port () {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return this._url.port.toString(10)
|
|
102
|
+
return this._slice(this._components[3] + 1 /* : */, this._components[5])
|
|
105
103
|
}
|
|
106
104
|
|
|
107
105
|
set port (value) {
|
|
108
|
-
if (this._url.host === null || this._url.host === '' || this._url.scheme === 'file') {
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (value === '') {
|
|
113
|
-
this._url.port = null
|
|
114
|
-
} else {
|
|
115
|
-
parse(value, null, this._url, constants.STATE_PORT)
|
|
116
|
-
}
|
|
117
106
|
}
|
|
118
107
|
|
|
119
108
|
// https://url.spec.whatwg.org/#dom-url-pathname
|
|
120
109
|
|
|
121
110
|
get pathname () {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
let output = ''
|
|
125
|
-
|
|
126
|
-
for (const segment of this._url.path) output += '/' + segment
|
|
127
|
-
|
|
128
|
-
return output
|
|
111
|
+
return this._slice(this._components[5], this._components[6] - 1 /* ? */)
|
|
129
112
|
}
|
|
130
113
|
|
|
131
114
|
set pathname (value) {
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
if (value[0] !== '/' && value[0] !== '\\') {
|
|
116
|
+
value = '/' + value
|
|
117
|
+
}
|
|
135
118
|
|
|
136
|
-
|
|
119
|
+
this._update(this._replace(value, this._components[5], this._components[6] - 1 /* ? */))
|
|
137
120
|
}
|
|
138
121
|
|
|
139
122
|
// https://url.spec.whatwg.org/#dom-url-search
|
|
140
123
|
|
|
141
124
|
get search () {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return '?' + this._url.query
|
|
125
|
+
return this._slice(this._components[6] - 1 /* ? */, this._components[7] - 1 /* # */)
|
|
145
126
|
}
|
|
146
127
|
|
|
147
128
|
set search (value) {
|
|
148
|
-
if (value === '') {
|
|
149
|
-
this._url.query = null
|
|
150
|
-
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (value.charCodeAt(0) === 0x3f) {
|
|
155
|
-
value = value.substring(1)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this._url.query = ''
|
|
159
|
-
|
|
160
|
-
parse(value, null, this._url, constants.STATE_QUERY)
|
|
161
129
|
}
|
|
162
130
|
|
|
163
131
|
// https://url.spec.whatwg.org/#dom-url-hash
|
|
164
132
|
|
|
165
133
|
get hash () {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return '#' + this._url.fragment
|
|
134
|
+
return this._slice(this._components[7] - 1 /* # */)
|
|
169
135
|
}
|
|
170
136
|
|
|
171
137
|
set hash (value) {
|
|
172
|
-
if (value === '') {
|
|
173
|
-
this._url.fragment = null
|
|
174
|
-
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (value.charCodeAt(0) === 0x23) {
|
|
179
|
-
value = value.substring(1)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
this._url.fragment = ''
|
|
183
|
-
|
|
184
|
-
parse(value, null, this._url, constants.STATE_FRAGMENT)
|
|
185
138
|
}
|
|
186
139
|
|
|
187
140
|
[Symbol.for('bare.inspect')] () {
|
|
@@ -200,6 +153,37 @@ const URL = exports.URL = class URL {
|
|
|
200
153
|
hash: this.hash
|
|
201
154
|
}
|
|
202
155
|
}
|
|
156
|
+
|
|
157
|
+
_slice (start, end) {
|
|
158
|
+
return this._href.slice(start, end)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_replace (replacement, start, end) {
|
|
162
|
+
return this._slice(0, start) + replacement + this._slice(end)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
_parse (href, base) {
|
|
166
|
+
try {
|
|
167
|
+
this._href = binding.parse(href, base, this._components)
|
|
168
|
+
} catch (err) {
|
|
169
|
+
safetyCatch(err)
|
|
170
|
+
|
|
171
|
+
throw errors.INVALID_URL()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
_update (href) {
|
|
176
|
+
try {
|
|
177
|
+
this._parse(href, null)
|
|
178
|
+
} catch (err) {
|
|
179
|
+
safetyCatch(err)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
|
|
185
|
+
function cannotHaveCredentialsOrPort (url) {
|
|
186
|
+
return url.hostname === '' || url.protocol === 'file:'
|
|
203
187
|
}
|
|
204
188
|
|
|
205
189
|
exports.fileURLToPath = function fileURLToPath (url) {
|
package/lib/errors.js
CHANGED
|
@@ -19,109 +19,4 @@ module.exports = class URLError extends Error {
|
|
|
19
19
|
static INVALID_URL_SCHEME (msg = 'Invalid URL') {
|
|
20
20
|
return new URLError(msg, 'INVALID_URL_SCHEME', URLError.INVALID_URL_SCHEME)
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
// https://url.spec.whatwg.org/#missing-scheme-non-relative-url
|
|
24
|
-
static MISSING_SCHEME_NON_RELATIVE_URL (msg = 'Invalid URL') {
|
|
25
|
-
return new URLError(msg, 'MISSING_SCHEME_NON_RELATIVE_URL', URLError.MISSING_SCHEME_NON_RELATIVE_URL)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// https://url.spec.whatwg.org/#invalid-credentials
|
|
29
|
-
static INVALID_CREDENTIALS (msg = 'Invalid URL') {
|
|
30
|
-
return new URLError(msg, 'INVALID_CREDENTIALS', URLError.INVALID_CREDENTIALS)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// https://url.spec.whatwg.org/#host-missing
|
|
34
|
-
static HOST_MISSING (msg = 'Invalid URL') {
|
|
35
|
-
return new URLError(msg, 'HOST_MISSING', URLError.HOST_MISSING)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// https://url.spec.whatwg.org/#port-out-of-range
|
|
39
|
-
static PORT_OUT_OF_RANGE (msg = 'Invalid URL') {
|
|
40
|
-
return new URLError(msg, 'PORT_OUT_OF_RANGE', URLError.PORT_OUT_OF_RANGE)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// https://url.spec.whatwg.org/#port-invalid
|
|
44
|
-
static PORT_INVALID (msg = 'Invalid URL') {
|
|
45
|
-
return new URLError(msg, 'PORT_INVALID', URLError.PORT_INVALID)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// https://url.spec.whatwg.org/#validation-error-domain-to-ascii
|
|
49
|
-
static DOMAIN_TO_ASCII (msg = 'Invalid URL') {
|
|
50
|
-
return new URLError(msg, 'DOMAIN_TO_ASCII', URLError.DOMAIN_TO_ASCII)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// https://url.spec.whatwg.org/#domain-invalid-code-point
|
|
54
|
-
static DOMAIN_INVALID_CODE_POINT (msg = 'Invalid URL') {
|
|
55
|
-
return new URLError(msg, 'DOMAIN_INVALID_CODE_POINT', URLError.DOMAIN_INVALID_CODE_POINT)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// https://url.spec.whatwg.org/#host-invalid-code-point
|
|
59
|
-
static HOST_INVALID_CODE_POINT (msg = 'Invalid URL') {
|
|
60
|
-
return new URLError(msg, 'HOST_INVALID_CODE_POINT', URLError.HOST_INVALID_CODE_POINT)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// https://url.spec.whatwg.org/#ipv4-too-many-parts
|
|
64
|
-
static IPV4_TOO_MANY_PARTS (msg = 'Invalid URL') {
|
|
65
|
-
return new URLError(msg, 'IPV4_TOO_MANY_PARTS', URLError.IPV4_TOO_MANY_PARTS)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// https://url.spec.whatwg.org/#ipv4-non-numeric-part
|
|
69
|
-
static IPV4_NON_NUMERIC_PART (msg = 'Invalid URL') {
|
|
70
|
-
return new URLError(msg, 'IPV4_NON_NUMERIC_PART', URLError.IPV4_NON_NUMERIC_PART)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// https://url.spec.whatwg.org/#ipv4-out-of-range-part
|
|
74
|
-
static IPV4_OUT_OF_RANGE_PART (msg = 'Invalid URL') {
|
|
75
|
-
return new URLError(msg, 'IPV4_OUT_OF_RANGE_PART', URLError.IPV4_OUT_OF_RANGE_PART)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// https://url.spec.whatwg.org/#ipv6-unclosed
|
|
79
|
-
static IPV6_UNCLOSED (msg = 'Invalid URL') {
|
|
80
|
-
return new URLError(msg, 'IPV6_UNCLOSED', URLError.IPV6_UNCLOSED)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// https://url.spec.whatwg.org/#ipv6-invalid-compression
|
|
84
|
-
static IPV6_INVALID_COMPRESSION (msg = 'Invalid URL') {
|
|
85
|
-
return new URLError(msg, 'IPV6_INVALID_COMPRESSION', URLError.IPV6_INVALID_COMPRESSION)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// https://url.spec.whatwg.org/#ipv6-too-many-pieces
|
|
89
|
-
static IPV6_TOO_MANY_PIECES (msg = 'Invalid URL') {
|
|
90
|
-
return new URLError(msg, 'IPV6_TOO_MANY_PIECES', URLError.IPV6_TOO_MANY_PIECES)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// https://url.spec.whatwg.org/#ipv6-multiple-compression
|
|
94
|
-
static IPV6_MULTIPLE_COMPRESSION (msg = 'Invalid URL') {
|
|
95
|
-
return new URLError(msg, 'IPV6_MULTIPLE_COMPRESSION', URLError.IPV6_MULTIPLE_COMPRESSION)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// https://url.spec.whatwg.org/#ipv6-invalid-code-point
|
|
99
|
-
static IPV6_INVALID_CODE_POINT (msg = 'Invalid URL') {
|
|
100
|
-
return new URLError(msg, 'IPV6_INVALID_CODE_POINT', URLError.IPV6_INVALID_CODE_POINT)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// https://url.spec.whatwg.org/#ipv6-too-few-pieces
|
|
104
|
-
static IPV6_TOO_FEW_PIECES (msg = 'Invalid URL') {
|
|
105
|
-
return new URLError(msg, 'IPV6_TOO_FEW_PIECES', URLError.IPV6_TOO_FEW_PIECES)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// https://url.spec.whatwg.org/#ipv4-in-ipv6-too-many-pieces
|
|
109
|
-
static IPV4_IN_IPV6_TOO_MANY_PIECES (msg = 'Invalid URL') {
|
|
110
|
-
return new URLError(msg, 'IPV4_IN_IPV6_TOO_MANY_PIECES', URLError.IPV4_IN_IPV6_TOO_MANY_PIECES)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// https://url.spec.whatwg.org/#ipv4-in-ipv6-invalid-code-point
|
|
114
|
-
static IPV4_IN_IPV6_INVALID_CODE_POINT (msg = 'Invalid URL') {
|
|
115
|
-
return new URLError(msg, 'IPV4_IN_IPV6_INVALID_CODE_POINT', URLError.IPV4_IN_IPV6_INVALID_CODE_POINT)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// https://url.spec.whatwg.org/#ipv4-in-ipv6-out-of-range-part
|
|
119
|
-
static IPV4_IN_IPV6_OUT_OF_RANGE_PART (msg = 'Invalid URL') {
|
|
120
|
-
return new URLError(msg, 'IPV4_IN_IPV6_OUT_OF_RANGE_PART', URLError.IPV4_IN_IPV6_OUT_OF_RANGE_PART)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// https://url.spec.whatwg.org/#ipv4-in-ipv6-too-few-parts
|
|
124
|
-
static IPV4_IN_IPV6_TOO_FEW_PARTS (msg = 'Invalid URL') {
|
|
125
|
-
return new URLError(msg, 'IPV4_IN_IPV6_TOO_FEW_PARTS', URLError.IPV4_IN_IPV6_TOO_FEW_PARTS)
|
|
126
|
-
}
|
|
127
22
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-url",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "URL parser for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"index.js",
|
|
8
|
-
"
|
|
8
|
+
"binding.c",
|
|
9
|
+
"binding.js",
|
|
10
|
+
"CMakeLists.txt",
|
|
11
|
+
"lib",
|
|
12
|
+
"prebuilds",
|
|
13
|
+
"vendor/liburl/include",
|
|
14
|
+
"vendor/liburl/src",
|
|
15
|
+
"vendor/libutf/include",
|
|
16
|
+
"vendor/libutf/src"
|
|
9
17
|
],
|
|
18
|
+
"addon": {
|
|
19
|
+
"target": "bare_url"
|
|
20
|
+
},
|
|
10
21
|
"scripts": {
|
|
11
22
|
"test": "standard && bare test.js"
|
|
12
23
|
},
|
|
@@ -23,7 +34,7 @@
|
|
|
23
34
|
"dependencies": {
|
|
24
35
|
"bare-os": "^2.0.0",
|
|
25
36
|
"bare-path": "^2.0.0",
|
|
26
|
-
"
|
|
37
|
+
"safety-catch": "^1.0.2"
|
|
27
38
|
},
|
|
28
39
|
"devDependencies": {
|
|
29
40
|
"brittle": "^3.3.2",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.25)
|
|
2
|
+
|
|
3
|
+
project(url C)
|
|
4
|
+
|
|
5
|
+
if(NOT TARGET utf)
|
|
6
|
+
add_subdirectory(vendor/libutf EXCLUDE_FROM_ALL)
|
|
7
|
+
endif()
|
|
8
|
+
|
|
9
|
+
add_library(url OBJECT)
|
|
10
|
+
|
|
11
|
+
set_target_properties(
|
|
12
|
+
url
|
|
13
|
+
PROPERTIES
|
|
14
|
+
C_STANDARD 11
|
|
15
|
+
POSITION_INDEPENDENT_CODE ON
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
target_sources(
|
|
19
|
+
url
|
|
20
|
+
INTERFACE
|
|
21
|
+
include/url.h
|
|
22
|
+
PRIVATE
|
|
23
|
+
src/character-set.h
|
|
24
|
+
src/infra.h
|
|
25
|
+
src/parse.h
|
|
26
|
+
src/percent-encode.h
|
|
27
|
+
src/serialize.h
|
|
28
|
+
src/type.h
|
|
29
|
+
src/url.c
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
target_include_directories(
|
|
33
|
+
url
|
|
34
|
+
PUBLIC
|
|
35
|
+
include
|
|
36
|
+
$<TARGET_PROPERTY:utf,INTERFACE_INCLUDE_DIRECTORIES>
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
add_library(url_shared SHARED)
|
|
40
|
+
|
|
41
|
+
set_target_properties(
|
|
42
|
+
url_shared
|
|
43
|
+
PROPERTIES
|
|
44
|
+
OUTPUT_NAME url
|
|
45
|
+
WINDOWS_EXPORT_ALL_SYMBOLS ON
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
target_link_libraries(
|
|
49
|
+
url_shared
|
|
50
|
+
PUBLIC
|
|
51
|
+
url
|
|
52
|
+
utf_shared
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
add_library(url_static STATIC)
|
|
56
|
+
|
|
57
|
+
set_target_properties(
|
|
58
|
+
url_static
|
|
59
|
+
PROPERTIES
|
|
60
|
+
OUTPUT_NAME url
|
|
61
|
+
PREFIX lib
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
target_link_libraries(
|
|
65
|
+
url_static
|
|
66
|
+
PUBLIC
|
|
67
|
+
url
|
|
68
|
+
utf_static
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
install(TARGETS url_shared url_static)
|
|
72
|
+
|
|
73
|
+
install(FILES include/url.h DESTINATION include)
|
|
74
|
+
|
|
75
|
+
if(PROJECT_IS_TOP_LEVEL)
|
|
76
|
+
enable_testing()
|
|
77
|
+
add_subdirectory(bench)
|
|
78
|
+
add_subdirectory(test)
|
|
79
|
+
endif()
|