antchfx/htmlquery

[bug] htmlquery.QueryAll not returning all node attribute results

bnkai opened this issue · 2 comments

bnkai commented

It seems that the nodup fix from #6 causes attributes that have the same value with the first result to be discarded
Example (only used for testing) taken from #20 and adjusted

package main

import (
        "fmt"
        "strings"

        "github.com/antchfx/htmlquery"
)

func main() {
        t := []string{
                "<span class='output' sup='24'></span><span class='output' sup='24'></span><span class='output' sup='45'></span>",
                "<span class='output' sup='24'></span><span class='output' sup='45'></span><span class='output' sup='45'></span>",
                "<span class='output' sup='45'></span><span class='output' sup='24'></span><span class='output' sup='45'></span>",
        }

        for _, s := range t {
                doc, _ := htmlquery.Parse(strings.NewReader(s))
                nx, _ := htmlquery.QueryAll(doc, "//span[@class='output']/@sup")
                for _, n := range nx {
                        fmt.Println(htmlquery.InnerText(n))
                }
                fmt.Println("--")
        }
}

Output

24
45
--
24
45
45
--
45
24
--

Expected Output

24
24
45
--
24
45
45
--
45
24
45
--

Thanks report, I removed the duplicate node checking. It can works now.

bnkai commented

That was fast! Thanks for the fix.