Commit 77d0c0a
committed
Fix YAML dump incorrectly handling zero values
In PHP, empty(0) and empty("0") return true, which caused the YAML
dumper to incorrectly treat zero values as empty. This resulted in:
- Arrays containing 0 being serialized without the zero value
- Scalar zero values being omitted from YAML output
Changes:
- dump(): Replace 'if ($array)' with explicit null/empty checks to
properly handle arrays that may contain zero values
- _yamlize(): Replace 'empty($value)' with 'count($value) === 0' to
only treat actually empty arrays as empty, not zero values
Added test cases:
- testDumpIntegerZero: Verify integer 0 is correctly dumped
- testDumpStringZero: Verify string '0' is correctly dumped
- testDumpAssociativeZero: Verify zero values in associative arrays
- testDumpMixedWithZero: Verify mixed arrays containing zero
Fixes wp-cli/wp-cli#61881 parent 17b6825 commit 77d0c0a
2 files changed
Lines changed: 45 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
215 | 217 | | |
216 | 218 | | |
217 | 219 | | |
| |||
234 | 236 | | |
235 | 237 | | |
236 | 238 | | |
237 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
196 | 235 | | |
0 commit comments