bare-url 1.0.10 → 1.1.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.
- package/binding.c +84 -14
- package/index.js +14 -4
- package/package.json +1 -1
- 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/binding.c
CHANGED
|
@@ -37,17 +37,16 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
37
37
|
assert(err == 0);
|
|
38
38
|
|
|
39
39
|
err = url_parse(&base, input, len, NULL);
|
|
40
|
-
if (err < 0) {
|
|
41
|
-
free(input);
|
|
42
40
|
|
|
41
|
+
free(input);
|
|
42
|
+
|
|
43
|
+
if (err < 0) {
|
|
43
44
|
url_destroy(&base);
|
|
44
45
|
|
|
45
46
|
js_throw_error(env, NULL, "Invalid base URL");
|
|
46
47
|
|
|
47
48
|
return NULL;
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
free(input);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
size_t len;
|
|
@@ -68,9 +67,10 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
68
67
|
url_init(&url);
|
|
69
68
|
|
|
70
69
|
err = url_parse(&url, input, len, has_base ? &base : NULL);
|
|
71
|
-
if (err < 0) {
|
|
72
|
-
free(input);
|
|
73
70
|
|
|
71
|
+
free(input);
|
|
72
|
+
|
|
73
|
+
if (err < 0) {
|
|
74
74
|
url_destroy(&base);
|
|
75
75
|
url_destroy(&url);
|
|
76
76
|
|
|
@@ -79,8 +79,6 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
79
79
|
return NULL;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
free(input);
|
|
83
|
-
|
|
84
82
|
js_value_t *href;
|
|
85
83
|
err = js_create_string_utf8(env, url.href.data, url.href.len, &href);
|
|
86
84
|
assert(err == 0);
|
|
@@ -94,19 +92,91 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
static js_value_t *
|
|
97
|
-
|
|
95
|
+
bare_url_can_parse (js_env_t *env, js_callback_info_t *info) {
|
|
98
96
|
int err;
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
size_t argc = 2;
|
|
99
|
+
js_value_t *argv[2];
|
|
100
|
+
|
|
101
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
102
|
+
assert(err == 0);
|
|
103
|
+
|
|
104
|
+
assert(argc == 2);
|
|
105
|
+
|
|
106
|
+
bool has_base;
|
|
107
|
+
err = js_is_string(env, argv[1], &has_base);
|
|
108
|
+
assert(err == 0);
|
|
109
|
+
|
|
110
|
+
url_t base;
|
|
111
|
+
url_init(&base);
|
|
112
|
+
|
|
113
|
+
if (has_base) {
|
|
114
|
+
size_t len;
|
|
115
|
+
err = js_get_value_string_utf8(env, argv[1], NULL, 0, &len);
|
|
103
116
|
assert(err == 0);
|
|
104
117
|
|
|
105
|
-
|
|
118
|
+
utf8_t *input = malloc(len);
|
|
119
|
+
err = js_get_value_string_utf8(env, argv[1], input, len, NULL);
|
|
106
120
|
assert(err == 0);
|
|
121
|
+
|
|
122
|
+
err = url_parse(&base, input, len, NULL);
|
|
123
|
+
|
|
124
|
+
free(input);
|
|
125
|
+
|
|
126
|
+
if (err < 0) {
|
|
127
|
+
url_destroy(&base);
|
|
128
|
+
|
|
129
|
+
js_value_t *result;
|
|
130
|
+
err = js_get_boolean(env, false, &result);
|
|
131
|
+
assert(err == 0);
|
|
132
|
+
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
size_t len;
|
|
138
|
+
err = js_get_value_string_utf8(env, argv[0], NULL, 0, &len);
|
|
139
|
+
assert(err == 0);
|
|
140
|
+
|
|
141
|
+
utf8_t *input = malloc(len);
|
|
142
|
+
err = js_get_value_string_utf8(env, argv[0], input, len, NULL);
|
|
143
|
+
assert(err == 0);
|
|
144
|
+
|
|
145
|
+
url_t url;
|
|
146
|
+
url_init(&url);
|
|
147
|
+
|
|
148
|
+
err = url_parse(&url, input, len, has_base ? &base : NULL);
|
|
149
|
+
|
|
150
|
+
free(input);
|
|
151
|
+
|
|
152
|
+
url_destroy(&base);
|
|
153
|
+
url_destroy(&url);
|
|
154
|
+
|
|
155
|
+
js_value_t *result;
|
|
156
|
+
err = js_get_boolean(env, err == 0, &result);
|
|
157
|
+
assert(err == 0);
|
|
158
|
+
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static js_value_t *
|
|
163
|
+
bare_url_exports (js_env_t *env, js_value_t *exports) {
|
|
164
|
+
int err;
|
|
165
|
+
|
|
166
|
+
#define V(name, fn) \
|
|
167
|
+
{ \
|
|
168
|
+
js_value_t *val; \
|
|
169
|
+
err = js_create_function(env, name, -1, fn, NULL, &val); \
|
|
170
|
+
assert(err == 0); \
|
|
171
|
+
err = js_set_named_property(env, exports, name, val); \
|
|
172
|
+
assert(err == 0); \
|
|
107
173
|
}
|
|
108
174
|
|
|
175
|
+
V("parse", bare_url_parse)
|
|
176
|
+
V("canParse", bare_url_can_parse)
|
|
177
|
+
#undef V
|
|
178
|
+
|
|
109
179
|
return exports;
|
|
110
180
|
}
|
|
111
181
|
|
|
112
|
-
BARE_MODULE(bare_url,
|
|
182
|
+
BARE_MODULE(bare_url, bare_url_exports)
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const errors = require('./lib/errors')
|
|
|
6
6
|
|
|
7
7
|
const isWindows = Bare.platform === 'win32'
|
|
8
8
|
|
|
9
|
-
const URL = exports
|
|
9
|
+
const URL = module.exports = exports = class URL {
|
|
10
10
|
constructor (href, base) {
|
|
11
11
|
if (typeof href !== 'string') throw errors.INVALID_URL()
|
|
12
12
|
|
|
@@ -154,7 +154,7 @@ const URL = exports.URL = class URL {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
set search (value) {
|
|
157
|
-
if (value[0] !== '?') value = '?' + value
|
|
157
|
+
if (value && value[0] !== '?') value = '?' + value
|
|
158
158
|
|
|
159
159
|
this._update(this._replace(value, this._components[6] - 1 /* ? */, this._components[7] - 1 /* # */))
|
|
160
160
|
}
|
|
@@ -166,7 +166,7 @@ const URL = exports.URL = class URL {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
set hash (value) {
|
|
169
|
-
if (value[0] !== '#') value = '#' + value
|
|
169
|
+
if (value && value[0] !== '#') value = '#' + value
|
|
170
170
|
|
|
171
171
|
this._update(this._replace(value, this._components[7] - 1 /* # */))
|
|
172
172
|
}
|
|
@@ -206,7 +206,7 @@ const URL = exports.URL = class URL {
|
|
|
206
206
|
|
|
207
207
|
_parse (href, base) {
|
|
208
208
|
try {
|
|
209
|
-
this._href = binding.parse(href, base, this._components)
|
|
209
|
+
this._href = binding.parse(String(href), base ? String(base) : null, this._components)
|
|
210
210
|
} catch (err) {
|
|
211
211
|
safetyCatch(err)
|
|
212
212
|
|
|
@@ -233,6 +233,16 @@ function cannotHaveCredentialsOrPort (url) {
|
|
|
233
233
|
return url.hostname === '' || url.protocol === 'file:'
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
exports.URL = exports // For Node.js compatibility
|
|
237
|
+
|
|
238
|
+
exports.isURL = function isURL (value) {
|
|
239
|
+
return value instanceof URL
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
exports.canParse = function canParse (href, base) {
|
|
243
|
+
return binding.canParse(String(href), base ? String(base) : null)
|
|
244
|
+
}
|
|
245
|
+
|
|
236
246
|
exports.fileURLToPath = function fileURLToPath (url) {
|
|
237
247
|
if (typeof url === 'string') {
|
|
238
248
|
url = new URL(url)
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|