Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
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
beego
Commits
7283aead
Commit
7283aead
authored
Aug 24, 2016
by
astaxie
Committed by
GitHub
Aug 24, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2116 from raphael10241024/self
fix#2039 & test
parents
227678c2
0ad4038d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
input.go
context/input.go
+6
-3
input_test.go
context/input_test.go
+18
-0
No files found.
context/input.go
View file @
7283aead
...
...
@@ -590,12 +590,15 @@ func (input *BeegoInput) bindStruct(params *url.Values, key string, typ reflect.
result
:=
reflect
.
New
(
typ
)
.
Elem
()
fieldValues
:=
make
(
map
[
string
]
reflect
.
Value
)
for
reqKey
,
val
:=
range
*
params
{
if
!
strings
.
HasPrefix
(
reqKey
,
key
+
"."
)
{
var
fieldName
string
if
strings
.
HasPrefix
(
reqKey
,
key
+
"."
)
{
fieldName
=
reqKey
[
len
(
key
)
+
1
:
]
}
else
if
strings
.
HasPrefix
(
reqKey
,
key
+
"["
)
&&
reqKey
[
len
(
reqKey
)
-
1
]
==
']'
{
fieldName
=
reqKey
[
len
(
key
)
+
1
:
len
(
reqKey
)
-
1
]
}
else
{
continue
}
fieldName
:=
reqKey
[
len
(
key
)
+
1
:
]
if
_
,
ok
:=
fieldValues
[
fieldName
];
!
ok
{
// Time to bind this field. Get it and make sure we can set it.
fieldValue
:=
result
.
FieldByName
(
fieldName
)
...
...
context/input_test.go
View file @
7283aead
...
...
@@ -75,6 +75,24 @@ func TestParse(t *testing.T) {
fmt
.
Println
(
user
)
}
func
TestParse2
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/?user[0][Username]=Raph&user[1].Username=Leo&user[0].Password=123456&user[1][Password]=654321"
,
nil
)
beegoInput
:=
NewInput
()
beegoInput
.
Context
=
NewContext
()
beegoInput
.
Context
.
Reset
(
httptest
.
NewRecorder
(),
r
)
beegoInput
.
ParseFormOrMulitForm
(
1
<<
20
)
type
User
struct
{
Username
string
Password
string
}
var
users
[]
User
err
:=
beegoInput
.
Bind
(
&
users
,
"user"
)
fmt
.
Println
(
users
)
if
err
!=
nil
||
users
[
0
]
.
Username
!=
"Raph"
||
users
[
0
]
.
Password
!=
"123456"
||
users
[
1
]
.
Username
!=
"Leo"
||
users
[
1
]
.
Password
!=
"654321"
{
t
.
Fatal
(
"users info wrong"
)
}
}
func
TestSubDomain
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"http://www.example.com/?id=123&isok=true&ft=1.2&ol[0]=1&ol[1]=2&ul[]=str&ul[]=array&user.Name=astaxie"
,
nil
)
beegoInput
:=
NewInput
()
...
...
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