Skip to content

Commit

Permalink
fix non-English characters query: #106, #99
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Dec 16, 2024
1 parent b94a535 commit f7d323f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 2 additions & 4 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,20 +868,18 @@ func (s *scanner) scanNumber() float64 {

func (s *scanner) scanString() string {
var (
c = 0
end = s.curr
)
s.nextChar()
i := s.pos - s.currSize
if s.currSize > 1 {
c++
}
c := s.currSize
for s.curr != end {
if !s.nextChar() {
panic(errors.New("xpath: scanString got unclosed string"))
}
c += s.currSize
}
c -= 1
s.nextChar()
return s.text[i : i+c]
}
Expand Down
9 changes: 9 additions & 0 deletions xpath_expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,12 @@ func TestBUG_104(t *testing.T) {
test_xpath_count(t, book_example, `//author[1]`, 4)
test_xpath_values(t, book_example, `//author[1]/text()`, "Giada De Laurentiis", "J K. Rowling", "James McGovern", "Erik T. Ray")
}

func TestNonEnglishPredicateExpression(t *testing.T) {
// https://github.com/antchfx/xpath/issues/106
doc := createNode("", RootNode)
n := doc.createChildNode("h1", ElementNode)
n.addAttribute("id", "断点")
n.createChildNode("Hello,World!", TextNode)
test_xpath_count(t, doc, "//h1[@id='断点']", 1)
}

0 comments on commit f7d323f

Please sign in to comment.