Make starts-with? and ends-with? tolerate non-string args (return false)

Previously these primitives threw Eval_error if either arg was non-string.
Now they return false, preventing crashes when DOM attributes return nil
values during element processing (e.g. htmx-boot-subtree! iterating
elements with undefined attribute names).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-18 07:41:42 +00:00
parent f78a97960f
commit d4f74b5b02
3 changed files with 145 additions and 145 deletions

View File

@@ -346,13 +346,13 @@ let () =
| [String s; String prefix] ->
Bool (String.length s >= String.length prefix &&
String.sub s 0 (String.length prefix) = prefix)
| _ -> raise (Eval_error "starts-with?: 2 string args"));
| _ -> Bool false);
register "ends-with?" (fun args ->
match args with
| [String s; String suffix] ->
let sl = String.length s and xl = String.length suffix in
Bool (sl >= xl && String.sub s (sl - xl) xl = suffix)
| _ -> raise (Eval_error "ends-with?: 2 string args"));
| _ -> Bool false);
register "index-of" (fun args ->
match args with
| [String haystack; String needle] ->