Homec4science

Fix JSON encoding of PhutilSafeHTML for browser consumption

Authored by epriestley <git@epriestley.com> on Jan 29 2013, 03:11.

Description

Fix JSON encoding of PhutilSafeHTML for browser consumption

Summary:
If you run this code:

json_encode(array('tag' => phutil_tag('div', array())));

...you get this result, because json_encode() does not call toString() on objects:

{"tag":{}}

Instead, convert such objects to their underlying strings. Javelin has support for JX.HTML and for implicit conversion (which is kind of sketchy for other reasons) but it's sort of complicated (only happens on Ajax, not behaviors) and messy (not metadata-based), so ignore it for now.

We'll need to do something similar for serialization to the database. My plan there is just to throw on any objects. The only time we put HTML in the database is cache-related and those tiny number of callsites can manually handle it.

Test Plan: Various ajax things now receive the correct data.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T2432

Differential Revision: https://secure.phabricator.com/D4684

Details

Committed
epriestley <git@epriestley.com>Jan 29 2013, 03:11
Pushed
aubortJan 31 2017, 17:16
Parents
rPH47f2df5f5118: Fix most timeline escaping
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHfc4cb5735702: Fix JSON encoding of PhutilSafeHTML for browser consumption (authored by epriestley <git@epriestley.com>).Jan 29 2013, 03:11