Page MenuHomePhabricator

Add an optional mode for `PhutilJSONParser` to detect duplicate keys
ClosedPublic

Authored by joshuaspence on Jun 19 2014, 1:58 AM.
Tags
None
Referenced Files
F18767843: D9627.id23091.diff
Wed, Oct 8, 12:31 AM
F18747886: D9627.diff
Fri, Oct 3, 6:07 PM
F18711512: D9627.id23113.diff
Mon, Sep 29, 4:15 AM
F18631965: D9627.diff
Sep 16 2025, 5:07 PM
F18557880: D9627.id.diff
Sep 8 2025, 8:09 PM
F18514671: D9627.diff
Sep 5 2025, 10:43 AM
F18383079: D9627.id23117.diff
Aug 28 2025, 10:35 PM
F18363764: D9627.diff
Aug 27 2025, 5:19 PM
Subscribers

Details

Summary

Ref T5297. Change PhutilJSONParser to disallow duplicate keys by default. In addition, add an optional mode to allow duplicate keys. One important caveat here is that PhutilJSONParser will return the first value in the case of a duplicate, whereas json_decode will return the last value.

Depends on D9624.

Test Plan

Wrote and executed unit tests.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

joshuaspence retitled this revision from to Add an optional mode for `PhutilJSONParser` to detect duplicate keys.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
epriestley edited edge metadata.
This revision is now accepted and ready to land.Jun 19 2014, 6:01 PM
joshuaspence edited edge metadata.

I've changed this a bit since it was initially accepted.

epriestley edited edge metadata.
epriestley added inline comments.
src/parser/PhutilJSONParser.php
14–15

For consistency, return $this;.

This revision is now accepted and ready to land.Jun 20 2014, 1:38 AM