spinel_kit 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/spinel_kit/json_decoder.rb +51 -17
- data/lib/spinel_kit/version.rb +1 -1
- data/sig/spinel_kit/json_decoder.rbs +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd39c286c6d7c659824f19858df58b9ff2cf21c2d951bd9bbc109538fd99496a
|
|
4
|
+
data.tar.gz: 49d68b394bff6bbb0168b1d76db3eeeb452d42e854116b2908acde8ffe7c9a47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de3d1fe679ddd3221521c3fd0f24717d876e099996201b20064820b2bc239a911b685ffb4074718d9131a21838c01589fcbcc52899b585b1ade2d21e9fec97d5
|
|
7
|
+
data.tar.gz: d4b9fe75c8a99b233e43c66517ef0c9eb84087cb4b070ed5cc06b3f424d5dcf40aa82753890b50a170162983ffd2a6167eab85b8300946486ceff9c96821c2a2
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to SpinelKit are documented here.
|
|
4
4
|
|
|
5
|
+
## [0.2.1] - 2026-11-29
|
|
6
|
+
|
|
7
|
+
Maintenance release on the 0.2 line (the last with `SpinelKit::Json`; 0.3.0
|
|
8
|
+
retired the codec).
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **`SpinelKit::Json` decoder: `\uXXXX` escapes above ASCII decoded to `?`.**
|
|
12
|
+
`get_str` kept only the low byte of a two-digit escape and gave up on the
|
|
13
|
+
rest, so a body from a client that escapes non-ASCII (Python's
|
|
14
|
+
`json.dumps` by default) lost its text: `"\u00e9t\u00e9"` became `?t?`.
|
|
15
|
+
Escapes now decode to the UTF-8 bytes of the code point; a surrogate pair
|
|
16
|
+
is one code point; a surrogate on its own becomes U+FFFD. A malformed
|
|
17
|
+
escape still yields `?` and never raises.
|
|
18
|
+
|
|
5
19
|
## [0.2.0] - 2026-06-08
|
|
6
20
|
|
|
7
21
|
### Added
|
|
@@ -242,26 +242,23 @@ module SpinelKit
|
|
|
242
242
|
elsif esc == "f"
|
|
243
243
|
out = out + "\f"
|
|
244
244
|
elsif esc == "u"
|
|
245
|
-
# \
|
|
246
|
-
#
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
out = out + Json.byte_to_chr(b)
|
|
245
|
+
# \uXXXX -> the UTF-8 bytes of the code point; a high surrogate
|
|
246
|
+
# followed by a \uDC00..DFFF escape is one code point.
|
|
247
|
+
cp = Json.hex4(s, pos + 2)
|
|
248
|
+
if cp < 0
|
|
249
|
+
out = out + "?"
|
|
250
|
+
pos += 2
|
|
251
|
+
next
|
|
252
|
+
end
|
|
253
|
+
pos += 6
|
|
254
|
+
if cp >= 0xD800 && cp <= 0xDBFF && pos + 1 < s.length && s[pos] == "\\" && s[pos + 1] == "u"
|
|
255
|
+
lo = Json.hex4(s, pos + 2)
|
|
256
|
+
if lo >= 0xDC00 && lo <= 0xDFFF
|
|
257
|
+
cp = 0x10000 + ((cp - 0xD800) << 10) + (lo - 0xDC00)
|
|
259
258
|
pos += 6
|
|
260
|
-
next
|
|
261
259
|
end
|
|
262
260
|
end
|
|
263
|
-
out = out +
|
|
264
|
-
pos += 2
|
|
261
|
+
out = out + Json.cp_to_utf8(cp)
|
|
265
262
|
next
|
|
266
263
|
else
|
|
267
264
|
out = out + esc
|
|
@@ -275,6 +272,43 @@ module SpinelKit
|
|
|
275
272
|
out
|
|
276
273
|
end
|
|
277
274
|
|
|
275
|
+
# Four hex digits at s[at, 4] as an integer; -1 when they are not there.
|
|
276
|
+
def self.hex4(s, at)
|
|
277
|
+
if at + 3 >= s.length
|
|
278
|
+
return -1
|
|
279
|
+
end
|
|
280
|
+
v = 0
|
|
281
|
+
i = 0
|
|
282
|
+
while i < 4
|
|
283
|
+
h = Json.hex_nibble(s[at + i])
|
|
284
|
+
if h < 0
|
|
285
|
+
return -1
|
|
286
|
+
end
|
|
287
|
+
v = v * 16 + h
|
|
288
|
+
i += 1
|
|
289
|
+
end
|
|
290
|
+
v
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# A code point as UTF-8. A surrogate on its own is U+FFFD.
|
|
294
|
+
def self.cp_to_utf8(cp)
|
|
295
|
+
if cp < 0x80
|
|
296
|
+
return cp.chr
|
|
297
|
+
end
|
|
298
|
+
if cp >= 0xD800 && cp <= 0xDFFF
|
|
299
|
+
cp = 0xFFFD
|
|
300
|
+
end
|
|
301
|
+
if cp < 0x800
|
|
302
|
+
return ((0xC0 | (cp >> 6)).chr + (0x80 | (cp & 0x3F)).chr).force_encoding("UTF-8")
|
|
303
|
+
end
|
|
304
|
+
if cp < 0x10000
|
|
305
|
+
return ((0xE0 | (cp >> 12)).chr + (0x80 | ((cp >> 6) & 0x3F)).chr +
|
|
306
|
+
(0x80 | (cp & 0x3F)).chr).force_encoding("UTF-8")
|
|
307
|
+
end
|
|
308
|
+
((0xF0 | (cp >> 18)).chr + (0x80 | ((cp >> 12) & 0x3F)).chr +
|
|
309
|
+
(0x80 | ((cp >> 6) & 0x3F)).chr + (0x80 | (cp & 0x3F)).chr).force_encoding("UTF-8")
|
|
310
|
+
end
|
|
311
|
+
|
|
278
312
|
def self.hex_nibble(c)
|
|
279
313
|
if c >= "0" && c <= "9"
|
|
280
314
|
return c.getbyte(0) - "0".getbyte(0)
|
data/lib/spinel_kit/version.rb
CHANGED
|
@@ -13,6 +13,8 @@ module SpinelKit
|
|
|
13
13
|
def self.skip_value: (String s, Integer pos) -> Integer
|
|
14
14
|
def self.skip_container: (String s, Integer pos) -> Integer
|
|
15
15
|
def self.parse_str_value: (String s, Integer pos) -> String
|
|
16
|
+
def self.hex4: (String s, Integer at) -> Integer
|
|
17
|
+
def self.cp_to_utf8: (Integer cp) -> String
|
|
16
18
|
def self.hex_nibble: (String c) -> Integer
|
|
17
19
|
def self.byte_to_chr: (Integer n) -> String
|
|
18
20
|
def self.parse_int_value: (String s, Integer pos) -> Integer
|