Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize-space does not conform to the W3C recommendation #32

Closed
vovchynniko opened this issue Jan 28, 2019 · 1 comment
Closed

normalize-space does not conform to the W3C recommendation #32

vovchynniko opened this issue Jan 28, 2019 · 1 comment
Labels

Comments

@vovchynniko
Copy link

Hi @zhengchun,

I was working with your library and I've noticed the normalize-space function is not replacing internal whitespace characters with one space as per the spec:

https://www.w3.org/TR/1999/REC-xpath-19991116/#function-normalize-space

The normalize-space function returns the argument string with whitespace normalized by stripping leading and trailing whitespace and replacing sequences of whitespace characters by a single space. [...]

Here's the minimal Go code that reproduces the issue:

package main

import (
	"fmt"
	"github.com/antchfx/htmlquery"
	"os"
	"strings"
)

func mustSucceed(err error) {
	if err != nil {
		fmt.Printf("Error: %v", err)
		os.Exit(1)
	}
}

func main() {
	htmlDoc := `<!doctype html>
<html lang=en>
   <head>
       <meta charset=utf-8>
       <title></title>
   </head>
   <body>
       <div>Match
           me</div>
   </body>
</html>`

	root, err := htmlquery.Parse(strings.NewReader(htmlDoc))
	mustSucceed(err)

	node := htmlquery.FindOne(root, "//div[normalize-space(text())=\"Match me\"]")
	if node == nil {
		fmt.Printf("No matches")
	}
}

This would print No matches.

Thank you for your time and effort!

@zhengchun zhengchun added the bug label Jan 29, 2019
zhengchun added a commit that referenced this issue Jan 29, 2019
@zhengchun
Copy link
Contributor

fixed, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants