Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
fceb2d6e
Commit
fceb2d6e
authored
Oct 09, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #957: Json::encode() doesn't handle empty object correctly.
parent
aede3c9f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
20 deletions
+18
-20
BaseJson.php
framework/yii/helpers/BaseJson.php
+14
-20
JsonTest.php
tests/unit/framework/helpers/JsonTest.php
+4
-0
No files found.
framework/yii/helpers/BaseJson.php
View file @
fceb2d6e
...
@@ -81,32 +81,26 @@ class BaseJson
...
@@ -81,32 +81,26 @@ class BaseJson
*/
*/
protected
static
function
processData
(
$data
,
&
$expressions
,
$expPrefix
)
protected
static
function
processData
(
$data
,
&
$expressions
,
$expPrefix
)
{
{
if
(
is_array
(
$data
))
{
if
(
is_object
(
$data
))
{
foreach
(
$data
as
$key
=>
$value
)
{
if
(
is_array
(
$value
)
||
is_object
(
$value
))
{
$data
[
$key
]
=
static
::
processData
(
$value
,
$expressions
,
$expPrefix
);
}
}
return
$data
;
}
elseif
(
is_object
(
$data
))
{
if
(
$data
instanceof
JsExpression
)
{
if
(
$data
instanceof
JsExpression
)
{
$token
=
"!{[
$expPrefix
="
.
count
(
$expressions
)
.
']}!'
;
$token
=
"!{[
$expPrefix
="
.
count
(
$expressions
)
.
']}!'
;
$expressions
[
'"'
.
$token
.
'"'
]
=
$data
->
expression
;
$expressions
[
'"'
.
$token
.
'"'
]
=
$data
->
expression
;
return
$token
;
return
$token
;
}
else
{
}
$data
=
$data
instanceof
Arrayable
?
$data
->
toArray
()
:
get_object_vars
(
$data
);
$data
=
$data
instanceof
Arrayable
?
$data
->
toArray
()
:
get_object_vars
(
$data
);
$result
=
array
();
if
(
$data
===
array
()
&&
!
$data
instanceof
Arrayable
)
{
foreach
(
$data
as
$key
=>
$value
)
{
return
new
\stdClass
();
if
(
is_array
(
$value
)
||
is_object
(
$value
))
{
}
$result
[
$key
]
=
static
::
processData
(
$value
,
$expressions
,
$expPrefix
);
}
}
else
{
$result
[
$key
]
=
$value
;
if
(
is_array
(
$data
))
{
}
foreach
(
$data
as
$key
=>
$value
)
{
if
(
is_array
(
$value
)
||
is_object
(
$value
))
{
$data
[
$key
]
=
static
::
processData
(
$value
,
$expressions
,
$expPrefix
);
}
}
return
$result
;
}
}
}
else
{
return
$data
;
}
}
return
$data
;
}
}
}
}
tests/unit/framework/helpers/JsonTest.php
View file @
fceb2d6e
...
@@ -45,6 +45,10 @@ class JsonTest extends TestCase
...
@@ -45,6 +45,10 @@ class JsonTest extends TestCase
'b'
=>
new
JsExpression
(
$expression2
),
'b'
=>
new
JsExpression
(
$expression2
),
);
);
$this
->
assertSame
(
"
{
\"a\":[1,$expression1],\"b\":$expression2
}
"
,
Json
::
encode
(
$data
));
$this
->
assertSame
(
"
{
\"a\":[1,$expression1],\"b\":$expression2
}
"
,
Json
::
encode
(
$data
));
// https://github.com/yiisoft/yii2/issues/957
$data
=
(
object
)
null
;
$this
->
assertSame
(
'{}'
,
Json
::
encode
(
$data
));
}
}
public
function
testDecode
()
public
function
testDecode
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment