From b94c12dcca02bb72f3ee52bdf4ec37ac09c44974 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Jun 2026 01:36:40 +0000 Subject: [PATCH] Fix v0.1.3 regression: stop coercing stored string values v0.1.3 changed Vivification#vivify_value from a class-based case/when into a pattern-matching case/in that ran every stored value through INTEGER/FLOAT/DATELIKE regexes. Because vivify_value runs on every construction (#initialize -> #vivify) and every assignment (#[]=), this silently corrupted any string containing a digit: Flexor.new(address: "123 Main Street").address # => 123 Flexor.new(note: "call me at 3pm").note # => 0.0 Flexor.new(ts: "2023-01-15T10:30:00").ts # => 2023 The branch was also internally broken (the DATELIKE arm does `require "datetime"`, which does not exist, and calls `it` outside a block), but INTEGER matched date strings first so that arm was dead. No spec caught this because every string value in the suite is digit-free ("alice", "deep", "localhost", ...) and every digit-bearing datum is either already an Integer or nested inside an Array (which goes through the untouched vivify_array path). Restore vivify_value to pass non-Hash/Array values through unchanged, add regression coverage for construction and assignment of number-/date-like strings, and remove the stray root-level patterns_spec.rb left over from the abandoned coercion experiment. Bump version to 0.1.4 Release the v0.1.3 regression fix (string values were silently coerced to Integer/Float on every store). 0.1.3 should be considered broken. Add leading-zero and currency cases to coercion regression specs Broaden the v0.1.3 regression coverage with two more real-world strings the coercion destroyed: a leading-zero ZIP ("01970" -> 1970) and a currency value ("$19.99" -> 0.0). Verified failing on the 0.1.3 code and passing on the fix under Ruby 3.4.9. Guard array and serialization vivify paths against coercion Close the two coverage gaps the v0.1.3 regression exposed beyond construction/assignment: - Marshal and YAML round-trips of a number-like string value ("01970"): init_with and marshal_load both call vivify, so 0.1.3 corrupted deserialized strings too. These fail on 0.1.3, pass on the fix. - A number-like string inside an array: vivify_array was never broken, so this is a forward-guard against reintroducing coercion there. Revert "Guard array and serialization vivify paths against coercion" This reverts commit a027343. Those test additions were pushed without sign-off; backing them out restores the branch to the reviewed state (regression fix, version bump, and construction/assignment specs). --- lib/flexor/version.rb | 2 +- lib/flexor/vivification.rb | 13 ++------ patterns_spec.rb | 10 ------ spec/flexor/flexor_constructor_spec.rb | 42 ++++++++++++++++++++++++++ spec/flexor/flexor_writing_spec.rb | 14 +++++++++ 5 files changed, 59 insertions(+), 22 deletions(-) delete mode 100644 patterns_spec.rb diff --git a/lib/flexor/version.rb b/lib/flexor/version.rb index 98d90af..9b0affa 100644 --- a/lib/flexor/version.rb +++ b/lib/flexor/version.rb @@ -1,3 +1,3 @@ class Flexor - VERSION = "0.1.3".freeze + VERSION = "0.1.4".freeze end diff --git a/lib/flexor/vivification.rb b/lib/flexor/vivification.rb index c18faf5..51ac5d1 100644 --- a/lib/flexor/vivification.rb +++ b/lib/flexor/vivification.rb @@ -2,10 +2,6 @@ class Flexor ## # Methods for recursively converting raw Hashes and Arrays into Flexor objects. module Vivification - FLOAT = /[0-9.-]+/ - INTEGER = /^(?