Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
87bc9b53
Commit
87bc9b53
authored
Nov 13, 2009
by
Adam Langley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
json: fix addressing of slice indexes that are multiples of 8.
Fixes #147. R=rsc CC=golang-dev
https://golang.org/cl/152123
parent
3f7a3240
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
struct.go
src/pkg/json/struct.go
+1
-1
struct_test.go
src/pkg/json/struct_test.go
+31
-0
No files found.
src/pkg/json/struct.go
View file @
87bc9b53
...
@@ -154,7 +154,7 @@ func (b *structBuilder) Elem(i int) Builder {
...
@@ -154,7 +154,7 @@ func (b *structBuilder) Elem(i int) Builder {
return
&
structBuilder
{
val
:
v
.
Elem
(
i
)}
return
&
structBuilder
{
val
:
v
.
Elem
(
i
)}
}
}
case
*
reflect
.
SliceValue
:
case
*
reflect
.
SliceValue
:
if
i
>
v
.
Cap
()
{
if
i
>
=
v
.
Cap
()
{
n
:=
v
.
Cap
();
n
:=
v
.
Cap
();
if
n
<
8
{
if
n
<
8
{
n
=
8
n
=
8
...
...
src/pkg/json/struct_test.go
View file @
87bc9b53
...
@@ -6,6 +6,7 @@ package json
...
@@ -6,6 +6,7 @@ package json
import
(
import
(
"reflect"
;
"reflect"
;
"strconv"
;
"testing"
;
"testing"
;
)
)
...
@@ -101,3 +102,33 @@ func TestUnmarshal(t *testing.T) {
...
@@ -101,3 +102,33 @@ func TestUnmarshal(t *testing.T) {
check
(
t
,
reflect
.
DeepEqual
(
m
.
MapStruct
,
decodedMapStruct
),
"mapstruct"
,
m
.
MapStruct
);
check
(
t
,
reflect
.
DeepEqual
(
m
.
MapStruct
,
decodedMapStruct
),
"mapstruct"
,
m
.
MapStruct
);
check
(
t
,
reflect
.
DeepEqual
(
m
.
MapPtrStruct
,
decodedMapPtrStruct
),
"mapptrstruct"
,
m
.
MapPtrStruct
);
check
(
t
,
reflect
.
DeepEqual
(
m
.
MapPtrStruct
,
decodedMapPtrStruct
),
"mapptrstruct"
,
m
.
MapPtrStruct
);
}
}
type
Issue147Text
struct
{
Text
string
;
}
type
Issue147
struct
{
Test
[]
Issue147Text
;
}
const
issue147Input
=
`{"test": [{"text":"0"},{"text":"1"},{"text":"2"},
{"text":"3"},{"text":"4"},{"text":"5"},
{"text":"6"},{"text":"7"},{"text":"8"},
{"text":"9"},{"text":"10"},{"text":"11"},
{"text":"12"},{"text":"13"},{"text":"14"},
{"text":"15"},{"text":"16"},{"text":"17"},
{"text":"18"},{"text":"19"},{"text":"20"},
{"text":"21"},{"text":"22"},{"text":"23"},
{"text":"24"},{"text":"25"},{"text":"26"},
{"text":"27"},{"text":"28"},{"text":"29"}]}`
func
TestIssue147
(
t
*
testing
.
T
)
{
var
timeline
Issue147
;
Unmarshal
(
issue147Input
,
&
timeline
);
for
i
,
e
:=
range
timeline
.
Test
{
if
e
.
Text
!=
strconv
.
Itoa
(
i
)
{
t
.
Errorf
(
"index: %d got: %s want: %d"
,
i
,
e
.
Text
,
i
)
}
}
}
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