Changeset View
Changeset View
Standalone View
Standalone View
src/parser/PhutilJSON.php
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
* | * | ||||
* @param dict Value to format. | * @param dict Value to format. | ||||
* @param int Current depth, for indentation. | * @param int Current depth, for indentation. | ||||
* @return string Pretty-printed value. | * @return string Pretty-printed value. | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
private function encodeFormattedValue($value, $depth) { | private function encodeFormattedValue($value, $depth) { | ||||
if (is_array($value)) { | if (is_array($value)) { | ||||
if (empty($value) || array_keys($value) === range(0, count($value) - 1)) { | if (phutil_is_natural_list($value)) { | ||||
return $this->encodeFormattedArray($value, $depth); | return $this->encodeFormattedArray($value, $depth); | ||||
} else { | } else { | ||||
return $this->encodeFormattedObject($value, $depth); | return $this->encodeFormattedObject($value, $depth); | ||||
} | } | ||||
} else { | } else { | ||||
if (defined('JSON_UNESCAPED_SLASHES')) { | if (defined('JSON_UNESCAPED_SLASHES')) { | ||||
// If we have a new enough version of PHP, disable escaping of slashes | // If we have a new enough version of PHP, disable escaping of slashes | ||||
// when pretty-printing values. Escaping slashes can defuse an attack | // when pretty-printing values. Escaping slashes can defuse an attack | ||||
Show All 26 Lines |