Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
849e6f99
Commit
849e6f99
authored
Nov 17, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: do not crash accessing r.Form if ParseForm fails
Fixes #233. R=dsymonds1
https://golang.org/cl/154179
parent
4dfd7fdd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
7 deletions
+6
-7
src/pkg/http/request.go
src/pkg/http/request.go
+4
-6
src/pkg/http/request_test.go
src/pkg/http/request_test.go
+2
-1
No files found.
src/pkg/http/request.go
View file @
849e6f99
...
...
@@ -576,7 +576,7 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
return
req
,
nil
;
}
func
parseForm
(
query
string
)
(
m
map
[
string
][]
string
,
err
os
.
Error
)
{
func
parseForm
(
m
map
[
string
][]
string
,
query
string
)
(
err
os
.
Error
)
{
data
:=
make
(
map
[
string
]
*
vector
.
StringVector
);
for
_
,
kv
:=
range
strings
.
Split
(
query
,
"&"
,
0
)
{
kvPair
:=
strings
.
Split
(
kv
,
"="
,
2
);
...
...
@@ -599,7 +599,6 @@ func parseForm(query string) (m map[string][]string, err os.Error) {
vec
.
Push
(
value
);
}
m
=
make
(
map
[
string
][]
string
);
for
k
,
vec
:=
range
data
{
m
[
k
]
=
vec
.
Data
()
}
...
...
@@ -613,9 +612,9 @@ func (r *Request) ParseForm() (err os.Error) {
if
r
.
Form
!=
nil
{
return
}
r
.
Form
=
make
(
map
[
string
][]
string
);
var
query
string
;
switch
r
.
Method
{
case
"GET"
:
query
=
r
.
URL
.
RawQuery
...
...
@@ -628,7 +627,7 @@ func (r *Request) ParseForm() (err os.Error) {
case
"text/plain"
,
"application/x-www-form-urlencoded"
,
""
:
var
b
[]
byte
;
if
b
,
err
=
io
.
ReadAll
(
r
.
Body
);
err
!=
nil
{
return
return
err
}
query
=
string
(
b
);
// TODO(dsymonds): Handle multipart/form-data
...
...
@@ -636,8 +635,7 @@ func (r *Request) ParseForm() (err os.Error) {
return
&
badStringError
{
"unknown Content-Type"
,
ct
}
}
}
r
.
Form
,
err
=
parseForm
(
query
);
return
;
return
parseForm
(
r
.
Form
,
query
);
}
// FormValue returns the first value for the named component of the query.
...
...
src/pkg/http/request_test.go
View file @
849e6f99
...
...
@@ -33,7 +33,8 @@ var parseTests = []parseTest{
func
TestParseForm
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
parseTests
{
form
,
err
:=
parseForm
(
test
.
query
);
form
:=
make
(
map
[
string
][]
string
);
err
:=
parseForm
(
form
,
test
.
query
);
if
err
!=
nil
{
t
.
Errorf
(
"test %d: Unexpected error: %v"
,
i
,
err
);
continue
;
...
...
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