From 5e4bd47bf92e2fe151e3905ee8ab9972c9f70f8d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 16:24:56 +0900 Subject: fix(php-shim): render floats through php_gcvt serialize(), var_export() and the string cast each hand-rolled `format!("{}", f)`, which never emits PHP's exponential spelling and carries the wrong precision for the string cast. PHP writes 1.0E+20 where Rust writes 1e20, and (string) 1/3 is 0.33333333333333, not the shortest round-trip form. Delegate all three to smart_str_append_double, which shirabe-php-src already provides and shirabe-php-rpc's codec already used: precision -1 for serialize() and var_export(), 14 for the string cast. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-rpc/tests/oracle.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'crates/shirabe-php-rpc/tests/oracle.rs') diff --git a/crates/shirabe-php-rpc/tests/oracle.rs b/crates/shirabe-php-rpc/tests/oracle.rs index b98f2203..2785d715 100644 --- a/crates/shirabe-php-rpc/tests/oracle.rs +++ b/crates/shirabe-php-rpc/tests/oracle.rs @@ -73,6 +73,21 @@ fn encode_direction_matches_php_for_scalars_and_floats() { 5e-324, 1.0 / 3.0, 0.30000000000000004, + // The two edges of the plain-notation window, approached from both sides: PHP keeps a + // decimal exponent of -4..=16 in plain notation whatever the digit count, and the widest + // mantissa an f64 has does not push the large edge outwards. + 1e-3, + -1e-5, + 1.23456789e-5, + 0.00012345, + 1.2345678901234568e16, + 1.2345678901234567e19, + -1e17, + 1.5e17, + f64::MIN, + f64::MIN_POSITIVE, + f64::EPSILON, + 2.5e-323, f64::NAN, f64::INFINITY, f64::NEG_INFINITY, @@ -226,6 +241,10 @@ fn decode_direction_matches_php_serialize_output() { "return serialize([\"\\xff\\x00key\" => \"\\x80\\x81\", 0 => \"plain\"]);", // Floats straight from the PHP formatter. r#"return serialize([0.1, 2.0, 1e17, 1e-5, -0.0, NAN, INF, -INF, 1/3]);"#, + // Both edges of PHP's plain-notation window, plus the extremes of the f64 range. + r#"return serialize([1e-4, 1e-5, 1e16, 1e17, 1.2345678901234568e16, -1e17, + PHP_FLOAT_MAX, -PHP_FLOAT_MAX, PHP_FLOAT_MIN, PHP_FLOAT_EPSILON, + 5e-324, 2.5e-323]);"#, // A sparse int-keyed array (not a list). r#"return serialize([3 => "c", 1 => "a"]);"#, // Deep nesting built in a loop. -- cgit v1.3.1-4-g156e