mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
This PR addresses issue #18808 regarding locale-dependent JSON serialization in PHP.
### Problem
When the system environment is set to a locale that uses a comma as a decimal separator (like `de_DE`), `float` and `double` values were being serialized into JSON as `3,14` instead of `3.14`. This produced invalid JSON that could not be parsed by other systems.
### Solution
- Updated php/src/Google/Protobuf/Internal/GPBJsonWire.php to use `sprintf("%.*h", ...)` for formatting values. This ensures that the decimal separator is always a dot (`.`), making the output locale-independent.
- Added a new test case testJsonEncodeFloatLocaleIndependent in php/tests/EncodeDecodeTest.php. This test explicitly sets the locale to `de_DE` to verify that the fix works correctly and produces valid JSON.
### Verification
- [x] Added new regression test.
- [x] Verified that all PHP tests pass locally: `vendor/bin/phpunit php/tests/EncodeDecodeTest.php`
Fixes #18808
Closes #25329
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/25329 from khdkkhdd:18808-php-float-fix
|
||
|---|---|---|
| .. | ||
| generated_previous | ||
| proto | ||
| proto_previous | ||
| ArrayTest.php | ||
| compile_extension.sh | ||
| ComposerJsonTest.php | ||
| DebugInfoTest.php | ||
| DefaultValueTest.php | ||
| DescriptorsTest.php | ||
| EncodeDecodeTest.php | ||
| force_c_ext.php | ||
| gdb_test.sh | ||
| GeneratedClassTest.php | ||
| GeneratedPhpdocTest.php | ||
| MapFieldTest.php | ||
| memory_leak_test.php | ||
| memory_leak_test.sh | ||
| multirequest.php | ||
| multirequest.sh | ||
| PhpImplementationTest.php | ||
| test_base.php | ||
| test_util.php | ||
| valgrind.supp | ||
| WellKnownTest.php | ||
| WrapperTypeSettersTest.php | ||