fast-sfv 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90cb74e8053123147c23b43aa443d6333ea78cbdc8c6d9970ed95ff6ad4e753f
4
- data.tar.gz: 499c590966d3e9d28f8836e00aeac5df9a5b08763c2ece6aa333f1319bed4f64
3
+ metadata.gz: c038f41386c09fa8be9123a801e49bbfa2e51827024b0240c3a6075d74f1c8e4
4
+ data.tar.gz: c80c47ef6fc3312a443e48fffc5db0ebfbef2c197d0f1482fcba1bf6ba1cbd42
5
5
  SHA512:
6
- metadata.gz: eb59034105e9229c336bcf8689e3be8daaf5c306cb00ff8bcd121083fc683d70d2d75dd20d410b8a95146adb2dd07030150c4dc5afba9f82e3e2af661c240ad2
7
- data.tar.gz: b8505159289584452dab99436d67dadab6b3a1c9ab4f9ffb28e1cea95bacdffd05c282465971498d9f462a9f5eff14d851cf0f2fcd05246bc54e88f8ed76a3da
6
+ metadata.gz: a398395e55160c7aa41026cb286685c87f3af1cf71705db2d4c4a52cd1238d1a072c16d9ea1951ed780bc260b73546c6f22d168d3d83e58485a9f5df19d690b5
7
+ data.tar.gz: 82352cb33d48328c2bc69d2f5ea907a5faf983754c0812bad81c20d49774d1765f74bcbcb4e59b9670003624ff3db709666788ca8932ece3b7ea6c6fd746bd25
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1 (2026-11-27)
4
+
5
+ - Fixed: the emit boundary never sends a message into the value it is
6
+ checking — the boundary guards (`serialize_item`, `serialize_list`
7
+ and `serialize_dict`, and the inner-list, parameter, key, date and
8
+ display-string walks beneath them) read the value with the
9
+ never-dispatch forms (`case value when Klass`, `Module#===`), so a
10
+ classless value (a `BasicObject` descendant) at a boundary raises
11
+ the documented `SerializeError` instead of escaping the error
12
+ contract as a raw `NoMethodError` — the promise the errors module
13
+ carries. A method is sent into the value only after its type is
14
+ established; the message names the value's class, never a method
15
+ the value itself answers.
16
+ - Fixed: `regions_item`/`regions_list`/`regions_dict`'s shape
17
+ `ArgumentError` leads with the requirement — "the shape must be
18
+ :item, :list or :dictionary, received …" — the wording rule every
19
+ requirement message in the family now follows.
20
+ - Test: negative zero serializes unsigned — `-0.0` emits `"0.0"`
21
+ (§4.1.5 step 5: only a value less than zero carries a sign), now
22
+ pinned by a round-trip assertion.
23
+ - Docs: the API reference's `VERSION` pin matches the released
24
+ version again (it had stayed at `0.1.1` through 0.2.0).
25
+
3
26
  ## 0.2.0 (2026-11-26)
4
27
 
5
28
  - Fixed: non-ASCII-compatible field input no longer escapes the error
@@ -94,7 +94,7 @@ module Fast
94
94
  when :item then scan_item
95
95
  when :list then scan_list
96
96
  when :dictionary then scan_dictionary
97
- else raise ArgumentError, "the shape is :item, :list or :dictionary (got #{shape.inspect})"
97
+ else raise ArgumentError, "the shape must be :item, :list or :dictionary, received #{shape.inspect}"
98
98
  end
99
99
  freeze
100
100
  end
@@ -158,15 +158,21 @@ module Fast
158
158
  def emit_inner_list(output, inner_list)
159
159
  output << "("
160
160
  items = inner_list.items
161
- fail_serialize(output, "an inner list's items must be an Array (got #{shape(items)})") unless items.is_a?(Array)
162
-
163
- first = true
164
- items.each do |item|
165
- output << " " unless first
166
- first = false
167
- fail_serialize(output, "an inner list member must be an Item (got #{shape(item)})") unless item.is_a?(Item)
168
-
169
- emit_item(output, item)
161
+ case items
162
+ when Array
163
+ first = true
164
+ items.each do |item|
165
+ output << " " unless first
166
+ first = false
167
+ case item
168
+ when Item
169
+ emit_item(output, item)
170
+ else
171
+ fail_serialize(output, "an inner list member must be an Item (got #{shape(item)})")
172
+ end
173
+ end
174
+ else
175
+ fail_serialize(output, "an inner list's items must be an Array (got #{shape(items)})")
170
176
  end
171
177
  output << ")"
172
178
  emit_parameters(output, inner_list.params)
@@ -176,15 +182,18 @@ module Fast
176
182
  # unless the value is Boolean true — the ";key" short form. The
177
183
  # Hash's iteration order is the wire order.
178
184
  def emit_parameters(output, params)
179
- fail_serialize(output, "parameters must be a Hash (got #{shape(params)})") unless params.is_a?(Hash)
180
-
181
- params.each do |key, value|
182
- output << ";"
183
- emit_key(output, key)
184
- unless value.equal?(true)
185
- output << "="
186
- emit_bare_item(output, value)
185
+ case params
186
+ when Hash
187
+ params.each do |key, value|
188
+ output << ";"
189
+ emit_key(output, key)
190
+ unless value.equal?(true)
191
+ output << "="
192
+ emit_bare_item(output, value)
193
+ end
187
194
  end
195
+ else
196
+ fail_serialize(output, "parameters must be a Hash (got #{shape(params)})")
188
197
  end
189
198
  end
190
199
 
@@ -192,8 +201,16 @@ module Fast
192
201
  # continuation KEY_BODY — the class the parse path reads; then the
193
202
  # key's bytes are appended whole.
194
203
  def emit_key(output, key)
195
- fail_serialize(output, "a key must be a String (got #{shape(key)})") unless key.is_a?(String)
204
+ case key
205
+ when String
206
+ emit_key_bytes(output, key)
207
+ else
208
+ fail_serialize(output, "a key must be a String (got #{shape(key)})")
209
+ end
210
+ end
196
211
 
212
+ # The key's own byte walk — the String the case above handed in.
213
+ def emit_key_bytes(output, key)
197
214
  size = key.bytesize
198
215
  fail_serialize(output, "a key must not be empty") if size.zero?
199
216
  fail_serialize(output, "a key must start with a lowercase letter or '*'") unless KEY_FIRST[key.getbyte(0)]
@@ -449,9 +466,12 @@ module Fast
449
466
  def emit_date(output, value)
450
467
  output << "@"
451
468
  number = value.value
452
- fail_serialize(output, "a date's value must be an Integer (got #{shape(number)})") unless number.is_a?(Integer)
453
-
454
- emit_integer(output, number)
469
+ case number
470
+ when Integer
471
+ emit_integer(output, number)
472
+ else
473
+ fail_serialize(output, "a date's value must be an Integer (got #{shape(number)})")
474
+ end
455
475
  end
456
476
 
457
477
  # §4.1.11 Serializing a Display String: #value UTF-8-encoded (a
@@ -484,19 +504,21 @@ module Fast
484
504
  # arrives in another encoding, failed loudly when it cannot be.
485
505
  def display_text(output, value)
486
506
  text = value.value
487
- unless text.is_a?(String)
488
- fail_serialize(output, "a display string's value must be a String (got #{shape(text)})")
489
- end
490
- if text.encoding != Encoding::UTF_8
491
- begin
492
- text = text.encode(Encoding::UTF_8)
493
- rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError, Encoding::ConverterNotFoundError
494
- fail_serialize(output, "a display string must be Unicode text")
507
+ case text
508
+ when String
509
+ if text.encoding != Encoding::UTF_8
510
+ begin
511
+ text = text.encode(Encoding::UTF_8)
512
+ rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError, Encoding::ConverterNotFoundError
513
+ fail_serialize(output, "a display string must be Unicode text")
514
+ end
495
515
  end
496
- end
497
- fail_serialize(output, "a display string must be Unicode text") unless text.valid_encoding?
516
+ fail_serialize(output, "a display string must be Unicode text") unless text.valid_encoding?
498
517
 
499
- text
518
+ text
519
+ else
520
+ fail_serialize(output, "a display string's value must be a String (got #{shape(text)})")
521
+ end
500
522
  end
501
523
 
502
524
  # The number of base-10 digits of +magnitude+ (1 at zero): the
@@ -543,9 +565,12 @@ module Fast
543
565
  # token (a Symbol is wrong-typed input and raises), an ASCII-8BIT
544
566
  # String a byte sequence.
545
567
  def serialize_item(item)
546
- Serializer.fail_shape("an Item", item) unless item.is_a?(Item)
547
-
548
- Serializer.item_string(item)
568
+ case item
569
+ when Item
570
+ Serializer.item_string(item)
571
+ else
572
+ Serializer.fail_shape("an Item", item)
573
+ end
549
574
  end
550
575
 
551
576
  # Serializes an RFC 9651 List (§4.1, field_type "list") — the
@@ -557,10 +582,12 @@ module Fast
557
582
  # SerializeError; an Item is never empty, so only the containers
558
583
  # answer nil.
559
584
  def serialize_list(list)
560
- Serializer.fail_shape("an Array of Items and InnerLists", list) unless list.is_a?(Array)
561
- return nil if list.empty?
562
-
563
- Serializer.list_string(list)
585
+ case list
586
+ when Array
587
+ list.empty? ? nil : Serializer.list_string(list)
588
+ else
589
+ Serializer.fail_shape("an Array of Items and InnerLists", list)
590
+ end
564
591
  end
565
592
 
566
593
  # Serializes an RFC 9651 Dictionary (§4.1, field_type "dictionary") —
@@ -572,10 +599,12 @@ module Fast
572
599
  # Strict: a non-Hash input, a Symbol key or an unwrapped value
573
600
  # raises SerializeError.
574
601
  def serialize_dict(dict)
575
- Serializer.fail_shape("a Hash of String keys to Items and InnerLists", dict) unless dict.is_a?(Hash)
576
- return nil if dict.empty?
577
-
578
- Serializer.dictionary_string(dict)
602
+ case dict
603
+ when Hash
604
+ dict.empty? ? nil : Serializer.dictionary_string(dict)
605
+ else
606
+ Serializer.fail_shape("a Hash of String keys to Items and InnerLists", dict)
607
+ end
579
608
  end
580
609
  end
581
610
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fast
4
4
  module SFV
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast-sfv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Jacobs