Skip to content

Commit

Permalink
fix eqAndHtml bug
Browse files Browse the repository at this point in the history
  • Loading branch information
foolin committed Apr 22, 2020
1 parent 4e259b9 commit 18cded6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (builtin BuiltinFunctions) Eq(node *goquery.Selection, args ...string) (out
// eqAndAttr(index, name) reduces the set of matched elements to the one at the specified index, and attr() return string.
func (builtin BuiltinFunctions) EqAndAttr(node *goquery.Selection, args ...string) (out interface{}, err error) {
if len(args) <= 1 {
return "", fmt.Errorf("eq(index) must has index")
return "", fmt.Errorf("eq(index) must has index and attr name")
}
indexValue := strings.TrimSpace(args[0])
idx, err := strconv.Atoi(indexValue)
Expand All @@ -237,7 +237,7 @@ func (builtin BuiltinFunctions) EqAndAttr(node *goquery.Selection, args ...strin

// eqAndHtml(index) reduces the set of matched elements to the one at the specified index, and html() return string.
func (builtin BuiltinFunctions) EqAndHtml(node *goquery.Selection, args ...string) (out interface{}, err error) {
if len(args) <= 1 {
if len(args) <= 0 {
return "", fmt.Errorf("eq(index) must has index")
}
indexValue := strings.TrimSpace(args[0])
Expand All @@ -250,7 +250,7 @@ func (builtin BuiltinFunctions) EqAndHtml(node *goquery.Selection, args ...strin

// eqAndOutHtml(index) reduces the set of matched elements to the one at the specified index, and outHtml() return string.
func (builtin BuiltinFunctions) EqAndOutHtml(node *goquery.Selection, args ...string) (out interface{}, err error) {
if len(args) <= 1 {
if len(args) <= 0 {
return "", fmt.Errorf("eq(index) must has index")
}
indexValue := strings.TrimSpace(args[0])
Expand Down
4 changes: 4 additions & 0 deletions pagser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type PageData struct {
NavEachHtml []string `pagser:".navlink li->eachHtml()"`
NavEachOutHtml []string `pagser:".navlink li->eachOutHtml()"`
NavJoinString string `pagser:".navlink li->eachJoin(|)"`
NavEq string `pagser:".navlink li->eq(1)"`
NavEqAttr string `pagser:".navlink li->eqAndAttr(1, id)"`
NavEqHtml string `pagser:".navlink li->eqAndHtml(1)"`
NavEqOutHtml string `pagser:".navlink li->eqAndOutHtml(1)"`
WordsSplitArray []string `pagser:".words->split(|)"`
Value string `pagser:"input[name='feedback']->value()"`
SubPageData *SubPageData `pagser:".navlink li:last-child"`
Expand Down

0 comments on commit 18cded6

Please sign in to comment.