-
Notifications
You must be signed in to change notification settings - Fork 3
Fix YAML dump incorrectly handling zero values #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
77d0c0a
03948eb
d52abd6
98b9623
76408e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,4 +193,43 @@ public function testPerCentAndDoubleQuote() { | |
| $this->assertEquals ($awaiting, $dump); | ||
| } | ||
|
|
||
| /** | ||
| * Test that integer zero values are correctly dumped. | ||
| * This is a regression test for the issue where empty(0) returns true in PHP, | ||
| * causing zero values to be incorrectly treated as empty. | ||
| */ | ||
| public function testDumpIntegerZero() { | ||
| $dump = Spyc::YAMLDump(array(0)); | ||
| $awaiting = "---\n- 0\n"; | ||
| $this->assertEquals($awaiting, $dump); | ||
| } | ||
|
|
||
| /** | ||
| * Test that string zero values are correctly dumped. | ||
| * This is a regression test for the issue where empty("0") returns true in PHP. | ||
| */ | ||
| public function testDumpStringZero() { | ||
| $dump = Spyc::YAMLDump(array('0')); | ||
| $awaiting = "---\n- \"0\"\n"; | ||
| $this->assertEquals($awaiting, $dump); | ||
| } | ||
|
Comment on lines
+201
to
+215
|
||
|
|
||
| /** | ||
| * Test that associative arrays with zero values are correctly dumped. | ||
| */ | ||
| public function testDumpAssociativeZero() { | ||
| $dump = Spyc::YAMLDump(array('key' => 0)); | ||
| $awaiting = "---\nkey: 0\n"; | ||
| $this->assertEquals($awaiting, $dump); | ||
| } | ||
|
|
||
| /** | ||
| * Test that mixed arrays containing zero values are correctly dumped. | ||
| */ | ||
| public function testDumpMixedWithZero() { | ||
| $dump = Spyc::YAMLDump(array(1, 0, 2)); | ||
| $awaiting = "---\n- 1\n- 0\n- 2\n"; | ||
| $this->assertEquals($awaiting, $dump); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition still treats an empty string (
'') as “empty” and skips dumping it. That contradicts the PR description (“restrict empty handling to null and truly empty arrays”), and it means top-level empty-string scalars can’t be serialized even though nested empty strings are supported. Consider removing the!== ''check (and add/adjust tests if you intentionally want''to be skipped).