Skip to content

Commit aea032f

Browse files
authored
fix: null pointer in getEmptyRoomTypes (#53)
Signed-off-by: jiuxia211 <2064166368@qq.com>
1 parent 7a80ffa commit aea032f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

room.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ func (s *Student) getState(url string) (map[string]string, error) {
201201
// 获取教室类型
202202
func (s *Student) getEmptyRoomTypes(viewStateMap map[string]string, building string, req EmptyRoomReq) ([]string, map[string]string, error) {
203203
var res *html.Node
204+
var err error
204205
if building != "" {
205-
res, _ = s.PostWithIdentifier(constants.ClassroomQueryURL, map[string]string{
206+
res, err = s.PostWithIdentifier(constants.ClassroomQueryURL, map[string]string{
206207
"__VIEWSTATE": viewStateMap["VIEWSTATE"],
207208
"__EVENTVALIDATION": viewStateMap["EVENTVALIDATION"],
208209
"ctl00$TB_rq": req.Time,
@@ -217,7 +218,7 @@ func (s *Student) getEmptyRoomTypes(viewStateMap map[string]string, building str
217218
"ctl00$ContentPlaceHolder1$BT_search": "查询",
218219
})
219220
} else {
220-
res, _ = s.PostWithIdentifier(constants.ClassroomQueryURL, map[string]string{
221+
res, err = s.PostWithIdentifier(constants.ClassroomQueryURL, map[string]string{
221222
"__VIEWSTATE": viewStateMap["VIEWSTATE"],
222223
"__EVENTVALIDATION": viewStateMap["EVENTVALIDATION"],
223224
"ctl00$TB_rq": req.Time,
@@ -231,6 +232,13 @@ func (s *Student) getEmptyRoomTypes(viewStateMap map[string]string, building str
231232
"ctl00$ContentPlaceHolder1$BT_search": "查询",
232233
})
233234
}
235+
if err != nil {
236+
return nil, nil, err
237+
}
238+
if res == nil {
239+
return nil, nil, nil
240+
}
241+
234242
sel := htmlquery.Find(res, "//*[@id='jslxdpl']//option")
235243
var types []string
236244
for _, opt := range sel {
@@ -247,6 +255,9 @@ func (s *Student) getEmptyRoomTypes(viewStateMap map[string]string, building str
247255
}
248256

249257
func parseEmptyRoom(doc *html.Node) ([]string, error) {
258+
if doc == nil {
259+
return nil, nil
260+
}
250261
sel := htmlquery.Find(doc, "//*[@id='jsdpl']//option")
251262
var res []string
252263
for _, opt := range sel {

0 commit comments

Comments
 (0)