mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-01 06:52:14 +08:00
Check if response is nil pointer in NewDocumentFromResponse
This commit is contained in:
6
type.go
6
type.go
@@ -4,7 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"errors"
|
||||||
"code.google.com/p/go.net/html"
|
"code.google.com/p/go.net/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,6 +54,10 @@ func NewDocumentFromReader(r io.Reader) (*Document, error) {
|
|||||||
// It loads the specified response's document, parses it, and stores the root Document
|
// It loads the specified response's document, parses it, and stores the root Document
|
||||||
// node, ready to be manipulated. The response's body is closed on return.
|
// node, ready to be manipulated. The response's body is closed on return.
|
||||||
func NewDocumentFromResponse(res *http.Response) (*Document, error) {
|
func NewDocumentFromResponse(res *http.Response) (*Document, error) {
|
||||||
|
if res == nil {
|
||||||
|
return nil, errors.New("Response is nil pointer")
|
||||||
|
}
|
||||||
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
// Parse the HTML into nodes
|
// Parse the HTML into nodes
|
||||||
|
Reference in New Issue
Block a user