bare-url 2.5.0 → 2.5.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/binding.c +156 -3
- package/lib/url-search-params.js +11 -11
- package/package.json +2 -2
- package/prebuilds/android-arm/bare-url.bare +0 -0
- package/prebuilds/android-arm64/bare-url.bare +0 -0
- package/prebuilds/android-ia32/bare-url.bare +0 -0
- package/prebuilds/android-x64/bare-url.bare +0 -0
- package/prebuilds/darwin-arm64/bare-url.bare +0 -0
- package/prebuilds/darwin-x64/bare-url.bare +0 -0
- package/prebuilds/ios-arm64/bare-url.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
- package/prebuilds/ios-x64-simulator/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-arm64/bare-url.bare +0 -0
- package/prebuilds/win32-x64/bare-url.bare +0 -0
package/binding.c
CHANGED
|
@@ -5,11 +5,113 @@
|
|
|
5
5
|
#include <stdlib.h>
|
|
6
6
|
#include <string.h>
|
|
7
7
|
#include <url.h>
|
|
8
|
+
#include <url/character-set.h>
|
|
9
|
+
#include <url/percent-encode.h>
|
|
8
10
|
#include <utf.h>
|
|
9
11
|
#include <utf/string.h>
|
|
10
12
|
|
|
13
|
+
// https://url.spec.whatwg.org/#concept-urlencoded-byte-serializer
|
|
14
|
+
//
|
|
15
|
+
// Everything except ASCII alphanumerics and `*-._` is percent-encoded. A space
|
|
16
|
+
// (0x20) is a special case, encoded as `+` rather than `%20`, so it is left out
|
|
17
|
+
// of the set and handled separately below.
|
|
18
|
+
static url_character_set_t bare_url__form_urlencoded_percent_encode_set = {
|
|
19
|
+
// 00 01 02 03 04 05 06 07
|
|
20
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
21
|
+
// 08 09 0a 0b 0c 0d 0e 0f
|
|
22
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
23
|
+
// 10 11 12 13 14 15 16 17
|
|
24
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
25
|
+
// 18 19 1a 1b 1c 1d 1e 1f
|
|
26
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
27
|
+
// 20 21 22 23 24 25 26 27
|
|
28
|
+
0x00 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
29
|
+
// 28 29 2a 2b 2c 2d 2e 2f
|
|
30
|
+
0x01 | 0x02 | 0x00 | 0x08 | 0x10 | 0x00 | 0x00 | 0x80,
|
|
31
|
+
// 30 31 32 33 34 35 36 37
|
|
32
|
+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
|
|
33
|
+
// 38 39 3a 3b 3c 3d 3e 3f
|
|
34
|
+
0x00 | 0x00 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
35
|
+
// 40 41 42 43 44 45 46 47
|
|
36
|
+
0x01 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
|
|
37
|
+
// 48 49 4a 4b 4c 4d 4e 4f
|
|
38
|
+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
|
|
39
|
+
// 50 51 52 53 54 55 56 57
|
|
40
|
+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
|
|
41
|
+
// 58 59 5a 5b 5c 5d 5e 5f
|
|
42
|
+
0x00 | 0x00 | 0x00 | 0x08 | 0x10 | 0x20 | 0x40 | 0x00,
|
|
43
|
+
// 60 61 62 63 64 65 66 67
|
|
44
|
+
0x01 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
|
|
45
|
+
// 68 69 6a 6b 6c 6d 6e 6f
|
|
46
|
+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
|
|
47
|
+
// 70 71 72 73 74 75 76 77
|
|
48
|
+
0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
|
|
49
|
+
// 78 79 7a 7b 7c 7d 7e 7f
|
|
50
|
+
0x00 | 0x00 | 0x00 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
51
|
+
// 80 81 82 83 84 85 86 87
|
|
52
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
53
|
+
// 88 89 8a 8b 8c 8d 8e 8f
|
|
54
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
55
|
+
// 90 91 92 93 94 95 96 97
|
|
56
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
57
|
+
// 98 99 9a 9b 9c 9d 9e 9f
|
|
58
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
59
|
+
// a0 a1 a2 a3 a4 a5 a6 a7
|
|
60
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
61
|
+
// a8 a9 aa ab ac ad ae af
|
|
62
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
63
|
+
// b0 b1 b2 b3 b4 b5 b6 b7
|
|
64
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
65
|
+
// b8 b9 ba bb bc bd be bf
|
|
66
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
67
|
+
// c0 c1 c2 c3 c4 c5 c6 c7
|
|
68
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
69
|
+
// c8 c9 ca cb cc cd ce cf
|
|
70
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
71
|
+
// d0 d1 d2 d3 d4 d5 d6 d7
|
|
72
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
73
|
+
// d8 d9 da db dc dd de df
|
|
74
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
75
|
+
// e0 e1 e2 e3 e4 e5 e6 e7
|
|
76
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
77
|
+
// e8 e9 ea eb ec ed ee ef
|
|
78
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
79
|
+
// f0 f1 f2 f3 f4 f5 f6 f7
|
|
80
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
81
|
+
// f8 f9 fa fb fc fd fe ff
|
|
82
|
+
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// https://url.spec.whatwg.org/#concept-urlencoded-serializer
|
|
86
|
+
static void
|
|
87
|
+
bare_url__serialize_form_urlencoded_component(js_env_t *env, js_value_t *value, utf8_string_t *result) {
|
|
88
|
+
int err;
|
|
89
|
+
|
|
90
|
+
size_t len;
|
|
91
|
+
err = js_get_value_string_utf8(env, value, NULL, 0, &len);
|
|
92
|
+
assert(err == 0);
|
|
93
|
+
|
|
94
|
+
utf8_t *input = malloc(len);
|
|
95
|
+
err = js_get_value_string_utf8(env, value, input, len, NULL);
|
|
96
|
+
assert(err == 0);
|
|
97
|
+
|
|
98
|
+
for (size_t i = 0; i < len; i++) {
|
|
99
|
+
utf8_t c = input[i];
|
|
100
|
+
|
|
101
|
+
if (c == 0x20 /* space */) {
|
|
102
|
+
err = utf8_string_append_character(result, '+');
|
|
103
|
+
} else {
|
|
104
|
+
err = url__percent_encode_character(c, bare_url__form_urlencoded_percent_encode_set, result);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
assert(err == 0);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
free(input);
|
|
111
|
+
}
|
|
112
|
+
|
|
11
113
|
static js_value_t *
|
|
12
|
-
bare_url_parse
|
|
114
|
+
bare_url_parse(js_env_t *env, js_callback_info_t *info) {
|
|
13
115
|
int err;
|
|
14
116
|
|
|
15
117
|
size_t argc = 4;
|
|
@@ -96,7 +198,7 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
96
198
|
}
|
|
97
199
|
|
|
98
200
|
static js_value_t *
|
|
99
|
-
bare_url_can_parse
|
|
201
|
+
bare_url_can_parse(js_env_t *env, js_callback_info_t *info) {
|
|
100
202
|
int err;
|
|
101
203
|
|
|
102
204
|
size_t argc = 2;
|
|
@@ -164,7 +266,57 @@ bare_url_can_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
164
266
|
}
|
|
165
267
|
|
|
166
268
|
static js_value_t *
|
|
167
|
-
|
|
269
|
+
bare_url_serialize_form_urlencoded(js_env_t *env, js_callback_info_t *info) {
|
|
270
|
+
int err;
|
|
271
|
+
|
|
272
|
+
size_t argc = 1;
|
|
273
|
+
js_value_t *argv[1];
|
|
274
|
+
|
|
275
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
276
|
+
assert(err == 0);
|
|
277
|
+
|
|
278
|
+
assert(argc == 1);
|
|
279
|
+
|
|
280
|
+
uint32_t len;
|
|
281
|
+
err = js_get_array_length(env, argv[0], &len);
|
|
282
|
+
assert(err == 0);
|
|
283
|
+
|
|
284
|
+
utf8_string_t result;
|
|
285
|
+
utf8_string_init(&result);
|
|
286
|
+
|
|
287
|
+
for (uint32_t i = 0; i + 1 < len; i += 2) {
|
|
288
|
+
js_value_t *pair[2];
|
|
289
|
+
|
|
290
|
+
err = js_get_element(env, argv[0], i, &pair[0]);
|
|
291
|
+
assert(err == 0);
|
|
292
|
+
|
|
293
|
+
err = js_get_element(env, argv[0], i + 1, &pair[1]);
|
|
294
|
+
assert(err == 0);
|
|
295
|
+
|
|
296
|
+
if (i != 0) {
|
|
297
|
+
err = utf8_string_append_character(&result, '&');
|
|
298
|
+
assert(err == 0);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
bare_url__serialize_form_urlencoded_component(env, pair[0], &result);
|
|
302
|
+
|
|
303
|
+
err = utf8_string_append_character(&result, '=');
|
|
304
|
+
assert(err == 0);
|
|
305
|
+
|
|
306
|
+
bare_url__serialize_form_urlencoded_component(env, pair[1], &result);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
js_value_t *output;
|
|
310
|
+
err = js_create_string_utf8(env, result.data, result.len, &output);
|
|
311
|
+
assert(err == 0);
|
|
312
|
+
|
|
313
|
+
utf8_string_destroy(&result);
|
|
314
|
+
|
|
315
|
+
return output;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
static js_value_t *
|
|
319
|
+
bare_url_exports(js_env_t *env, js_value_t *exports) {
|
|
168
320
|
int err;
|
|
169
321
|
|
|
170
322
|
#define V(name, fn) \
|
|
@@ -178,6 +330,7 @@ bare_url_exports (js_env_t *env, js_value_t *exports) {
|
|
|
178
330
|
|
|
179
331
|
V("parse", bare_url_parse)
|
|
180
332
|
V("canParse", bare_url_can_parse)
|
|
333
|
+
V("serializeSearchParams", bare_url_serialize_form_urlencoded)
|
|
181
334
|
#undef V
|
|
182
335
|
|
|
183
336
|
return exports;
|
package/lib/url-search-params.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
|
|
1
3
|
const kind = Symbol.for('bare.url.search-params.kind')
|
|
2
4
|
|
|
3
5
|
class URLSearchParams {
|
|
@@ -30,7 +32,11 @@ class URLSearchParams {
|
|
|
30
32
|
|
|
31
33
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-size
|
|
32
34
|
get size() {
|
|
33
|
-
|
|
35
|
+
let size = 0
|
|
36
|
+
|
|
37
|
+
for (const values of this._params.values()) size += values.length
|
|
38
|
+
|
|
39
|
+
return size
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-append
|
|
@@ -169,19 +175,13 @@ class URLSearchParams {
|
|
|
169
175
|
|
|
170
176
|
// https://url.spec.whatwg.org/#concept-urlencoded-serializer
|
|
171
177
|
_serialize() {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
for (let [name, values] of this._params) {
|
|
175
|
-
name = encodeURIComponent(name)
|
|
178
|
+
const pairs = []
|
|
176
179
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
output += name + '=' + encodeURIComponent(value)
|
|
181
|
-
}
|
|
180
|
+
for (const [name, values] of this._params) {
|
|
181
|
+
for (const value of values) pairs.push(String(name), String(value))
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
return
|
|
184
|
+
return binding.serializeSearchParams(pairs)
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-url",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "WHATWG URL implementation for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package": "./package.json",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"brittle": "^3.3.2",
|
|
48
|
-
"cmake-bare": "^1.1
|
|
48
|
+
"cmake-bare": "^1.8.1",
|
|
49
49
|
"cmake-fetch": "^1.0.0",
|
|
50
50
|
"lunte": "^1.6.0",
|
|
51
51
|
"prettier": "^3.3.3",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|