mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 08:14:06 +02:00
Fix isJSON
Thanks to Drainedsoul
This commit is contained in:
@@ -1199,11 +1199,9 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function isJson()
|
||||
{
|
||||
if (!$this->endsWith('}') && !$this->endsWith(']')) {
|
||||
return false;
|
||||
}
|
||||
json_decode($this->str);
|
||||
|
||||
return !is_null(json_decode($this->str));
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -730,14 +730,14 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
public function isJsonProvider()
|
||||
{
|
||||
return array(
|
||||
array(false, ''),
|
||||
array(false, '123'),
|
||||
array(true, ''),
|
||||
array(true, '123'),
|
||||
array(true, '{"foo": "bar"}'),
|
||||
array(false, '{"foo":"bar",}'),
|
||||
array(false, '{"foo"}'),
|
||||
array(true, '["foo"]'),
|
||||
array(false, '{"foo": "bar"]'),
|
||||
array(false, '123', 'UTF-8'),
|
||||
array(true, '123', 'UTF-8'),
|
||||
array(true, '{"fòô": "bàř"}', 'UTF-8'),
|
||||
array(false, '{"fòô":"bàř",}', 'UTF-8'),
|
||||
array(false, '{"fòô"}', 'UTF-8'),
|
||||
|
Reference in New Issue
Block a user