Skip to content

Commit

Permalink
fix #102
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Jul 29, 2024
1 parent d37f8b2 commit 18b075e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,16 @@ func (b *builder) processFunction(root *functionNode, props *builderProp) (query
}
qyOutput = &functionQuery{Func: stringLengthFunc(arg1)}
case "normalize-space":
if len(root.Args) == 0 {
return nil, errors.New("xpath: normalize-space function must have at least one parameter")
var arg node
if len(root.Args) > 0 {
arg = root.Args[0]
} else {
arg = &axisNode{
AxeType: "self",
nodeType: nodeAxis,
}
}
argQuery, err := b.processNode(root.Args[0], flagsEnum.None, props)
argQuery, err := b.processNode(arg, flagsEnum.None, props)
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions xpath_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ func Test_func_namespace_uri(t *testing.T) {
func Test_func_normalize_space(t *testing.T) {
const testStr = "\t \rloooooooonnnnnnngggggggg \r \n tes \u00a0 t strin \n\n \r g "
const expectedStr = `loooooooonnnnnnngggggggg tes t strin g`
test_xpath_eval(t, employee_example, `normalize-space("`+testStr+`")`, expectedStr)

test_xpath_eval(t, empty_example, `normalize-space("`+testStr+`")`, expectedStr)
test_xpath_eval(t, empty_example, `normalize-space(' abc ')`, "abc")
n := selectNode(employee_example, `//employee[@id="1"]/name`)
test_xpath_eval(t, n, `normalize-space()`, "Opal Kole")
test_xpath_eval(t, n, `normalize-space(.)`, "Opal Kole")
test_xpath_eval(t, book_example, `normalize-space(//book/title)`, "Everyday Italian")
test_xpath_eval(t, book_example, `normalize-space(//book[1]/title)`, "Everyday Italian")

}

func Test_func_lower_case(t *testing.T) {
Expand Down

0 comments on commit 18b075e

Please sign in to comment.