Skip to content

Commit

Permalink
Fix invalid language's bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xalanq committed Aug 15, 2019
1 parent d80dac4 commit 2370bae
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
docopt "github.com/docopt/docopt-go"
)

const version = "v0.8.0"
const version = "v0.8.1"

func main() {
usage := `Codeforces Tool $%version%$ (cf). https://github.com/xalanq/cf-tool
Expand Down
14 changes: 9 additions & 5 deletions client/submit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -16,8 +17,8 @@ type SaveSubmission struct {
SubmissionID string `json:"submission_id"`
}

func findErrorSource(body []byte) ([]byte, error) {
reg := regexp.MustCompile(`"error\sfor__source">(.*?)</span>`)
func findErrorMessage(body []byte) ([]byte, error) {
reg := regexp.MustCompile(`error[a-zA-Z_\-\ ]*">(.*?)</span>`)
tmp := reg.FindSubmatch(body)
if tmp == nil {
return nil, errors.New("Cannot find error")
Expand Down Expand Up @@ -52,7 +53,7 @@ func (c *Client) SubmitContest(contestID, problemID, langID, source string) (err
return
}

resp, err = c.client.PostForm(fmt.Sprintf("%v?csrf=%v", URL, csrf), url.Values{
resp, err = c.client.PostForm(fmt.Sprintf("%v?csrf_token=%v", URL, csrf), url.Values{
"csrf_token": {csrf},
"ftaa": {c.Ftaa},
"bfaa": {c.Bfaa},
Expand All @@ -73,9 +74,12 @@ func (c *Client) SubmitContest(contestID, problemID, langID, source string) (err
if err != nil {
return
}
sourceError, err := findErrorSource(body)
errorMessage, err := findErrorMessage(body)
if err == nil {
return errors.New(string(sourceError))
return errors.New(string(errorMessage))
}
if !bytes.Contains(body, []byte("submitted successfully")) {
return errors.New("Submit failed")
}
color.Green("Submitted")

Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func getCode(args map[string]interface{}, templates []config.CodeTemplate) (code
func getOneCode(args map[string]interface{}, templates []config.CodeTemplate) (name string, index int, err error) {
codes := getCode(args, templates)
if len(codes) < 1 {
return "", 0, errors.New("Cannot find any supported code\nYou can add some suffixes by `cf config add`")
return "", 0, errors.New("Cannot find any code.\nMaybe you should add a new template by `cf config`")
}
if len(codes) > 1 {
color.Cyan("There are multiple files can be selected.")
Expand Down
2 changes: 1 addition & 1 deletion config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Config) AddTemplate() (err error) {
color.Cyan(`Select a language (e.g. "42"): `)
lang := ""
for {
lang := util.ScanlineTrim()
lang = util.ScanlineTrim()
if val, ok := client.Langs[lang]; ok {
color.Green(val)
break
Expand Down

0 comments on commit 2370bae

Please sign in to comment.