bare-url 2.4.7 → 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/CMakeLists.txt CHANGED
@@ -5,8 +5,11 @@ find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch)
5
5
 
6
6
  project(bare_url C)
7
7
 
8
- fetch_package("github:holepunchto/libutf#f0d532e")
9
- fetch_package("github:holepunchto/liburl#2f0e4c1")
8
+ fetch_package("github:holepunchto/libutf#a1ceca8")
9
+ fetch_package("github:holepunchto/libpunycode#e91ee34")
10
+ fetch_package("github:holepunchto/libnormalize#0e81f65")
11
+ fetch_package("github:holepunchto/libidna#1471406")
12
+ fetch_package("github:holepunchto/liburl#fc3abba")
10
13
 
11
14
  add_bare_module(bare_url)
12
15
 
@@ -20,8 +23,14 @@ target_link_libraries(
20
23
  ${bare_url}
21
24
  PRIVATE
22
25
  $<TARGET_OBJECTS:utf>
26
+ $<TARGET_OBJECTS:punycode>
27
+ $<TARGET_OBJECTS:normalize>
28
+ $<TARGET_OBJECTS:idna>
23
29
  $<TARGET_OBJECTS:url>
24
30
  PUBLIC
25
31
  utf
32
+ punycode
33
+ normalize
34
+ idna
26
35
  url
27
36
  )
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 (js_env_t *env, js_callback_info_t *info) {
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 (js_env_t *env, js_callback_info_t *info) {
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
- bare_url_exports (js_env_t *env, js_value_t *exports) {
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;
@@ -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
- return this._params.length
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
- let output = ''
173
-
174
- for (let [name, values] of this._params) {
175
- name = encodeURIComponent(name)
178
+ const pairs = []
176
179
 
177
- for (const value of values) {
178
- if (output) output += '&'
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 output
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.4.7",
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.6",
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