Convert a number or boolean argument with asString in four string functions - #144
Merged
Merged
Conversation
…ctions matches, normalize-space, substring and string-length switch only on string and query, so a number or boolean first argument fell through with an empty string. string-length(12345) returned 0, substring(12345, 2, 3) returned "" and normalize-space(false()) returned "". translate, replace, lower-case and concat already convert through asString, which formats numbers and booleans the way string() does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
matches,normalize-space,substringandstring-lengthswitch on the first argument's type with onlycase stringandcase query, so a number or boolean falls through and the function works on"".translate,replace,lower-caseandconcatalready convert throughasString(func.go:290), which formats numbers and booleans the waystring()does. This adds the samedefaultto the four that were missing it.In practice
substring(sum(//price), 1, 3)orstring-length(count(//item))quietly return empty. One behaviour change to call out:matches(1, '^$')wastrue, because the pattern ran against"", and is nowfalse.This is the neighbour I mentioned at the end of #141.
Verification
Base
5dbec0f. New cases go into the existingTest_func_string_length,Test_func_substring,Test_func_matchesandTest_func_normalize_space.func.gomd5fce2401a8e2c34dc9e76ec94f464dea079a94deca5d3d6f1599f0b8fdc6f2442fmt.Sprint(typ)instead ofasString87c3659419e6a37b831c39f507e672fcmatchesdefaultb773bbd55a438c876eeff698342bbf6anormalize-spacedefault458059f925b3e63bf67dbf3dff43cbfcsubstringdefaultbf06ca00efa58bdf901b666a255f3bf0string-lengthdefault7f63ef27c2c3279677ee70aca266df7fEach partial row fails on its own function alone, so all four sites are needed. The
fmt.Sprintrow is whysubstring(1 div 0, 1, 3)is in the table:fmt.Sprintgives+Inf,asStringgivesInfinity.testing.yml'sgo test ./...passes on go1.26.3.coverage.yml'sgo test -covermode atomic -coverprofile=coverage.out ./...passes on go1.16.15, the version it pins, at 85.3%.go vet ./...clean,gofmt -lempty for both files.Written with AI assistance (Claude); the measurements above were run locally and I have reviewed the change.