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:
@@ -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] ->
|
||||
|
||||
Reference in New Issue
Block a user