Commit 5642b5c9
5642b5c9c630Merged
NHH <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Fix String#split(" ") to use whitespace-split mode
"a b".split(" ") returned ["a", "", "b"] (literal space splitting) instead of ["a", "b"]. CRuby treats a single-space separator as whitespace-split mode — same as no-arg split — which strips leading whitespace and collapses consecutive whitespace. Route literal " " to sp_str_split_ws in the codegen, matching the existing nil-arg and no-arg paths.
Details
- Commit
- 5642b5c9c630
- Parent
- 155ec59a2269
spinel_codegen.rbmodifiedView file
@@ -21128,6 +21128,11 @@
2112821128
if @nd_type[a[0]] == "NilNode"2112921129
return "sp_str_split_ws(" + rc + ")"2113021130
end21131+
# CRuby special case: split(" ") is whitespace-split mode (strips21132+
# leading whitespace, collapses consecutive), not literal " " split.21133+
if @nd_type[a[0]] == "StringNode" && @nd_content[a[0]] == " "21134+
return "sp_str_split_ws(" + rc + ")"21135+
end2113121136
# Two-arg split(sep, limit) -- positive limit caps the result at2113221137
# that many elements with the last one holding the unsplit2113321138
# remainder. Issue #619 puzzle 2.test/str_split_space_whitespace.rbaddedView file
Loading diff…
test/str_split_space_whitespace.rb.expectedaddedView file
Loading diff…