Skip to content

Convert a number or boolean argument in substring-before and substring-after - #148

Merged
zhengchun merged 1 commit into
antchfx:masterfrom
youdie006:substring-ind-asstring
Oct 7, 2026
Merged

zhengchun merged 1 commit into
antchfx:masterfrom
youdie006:substring-ind-asstring

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

Follow-up to #144. substring-before and substring-after share substringIndFunc, which also switches on case string and case query only, for both arguments, so a number or boolean is read as "":

expression xmllint master
substring-before(12345, 3) 12 ""
substring-after(12345, 3) 45 ""
substring-after("a1b", 1) b ""
substring-before(true(), "u") tr ""
substring-after(1 div 0, "fin") ity ""

This adds the same default: asString(t, v) case to both switches. The new rows in Test_func_substring_after/_before fail on master; dropping either default fails them, and fmt.Sprint instead of asString fails the 1 div 0 row. go test ./... and go vet ./... pass. starts-with, ends-with and contains still panic on a number, which the tests from #134 expect, so I left them alone.

Written with AI assistance (Claude); I have reviewed the change.

…g-after

substringIndFunc only handled string and node-set arguments, so any other
value was read as "": substring-before(12345, 3) gave "" instead of "12".
Fall back to asString, as antchfx#144 did for the other string functions.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 83.868% (+0.02%) from 83.847% — youdie006:substring-ind-asstring into antchfx:master

@zhengchun
zhengchun merged commit 5c1e0f4 into antchfx:master Oct 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants