Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ func substringIndFunc(arg1, arg2 query, after bool) func(query, iterator) interf
return ""
}
str = node.Value()
default:
str = asString(t, v)
}
var word string
switch v := functionArgs(arg2).Evaluate(t).(type) {
Expand All @@ -567,6 +569,8 @@ func substringIndFunc(arg1, arg2 query, after bool) func(query, iterator) interf
return ""
}
word = node.Value()
default:
word = asString(t, v)
}
if word == "" {
return ""
Expand Down
5 changes: 5 additions & 0 deletions xpath_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ func Test_func_substring_after(t *testing.T) {
test_xpath_eval(t, empty_example, `substring-after(//non-existent-node, "tat")`, "")
test_xpath_eval(t, empty_example, `substring-after("tattoo", //non-existent-node)`, "")
test_xpath_eval(t, empty_example, `substring-after("", "tat")`, "")
test_xpath_eval(t, empty_example, `substring-after(12345, 3)`, "45")
test_xpath_eval(t, empty_example, `substring-after("a1b", 1)`, "b")
test_xpath_eval(t, empty_example, `substring-after(1 div 0, "fin")`, "ity")
}

func Test_func_substring_before(t *testing.T) {
Expand All @@ -230,6 +233,8 @@ func Test_func_substring_before(t *testing.T) {
test_xpath_eval(t, empty_example, `substring-before(//non-existent-node, "tat")`, "")
test_xpath_eval(t, empty_example, `substring-before("tattoo", //non-existent-node)`, "")
test_xpath_eval(t, empty_example, `substring-before("", "tat")`, "")
test_xpath_eval(t, empty_example, `substring-before(12345, 3)`, "12")
test_xpath_eval(t, empty_example, `substring-before(true(), "u")`, "tr")
}

func Test_func_sum(t *testing.T) {
Expand Down
Loading