mirror of
https://github.com/bigskysoftware/htmx.git
synced 2026-10-29 00:46:38 +08:00
hasHeader() tested a regex against getAllResponseHeaders() output, which
false-positively matched any header containing an htmx header name as a
substring — e.g. X-HX-Trigger or HX-Trigger-User. After the false-positive,
xhr.getResponseHeader('HX-Trigger') returned null, and handleTriggerHeader
crashed on triggerBody.indexOf('{').
Refactors hasHeader(xhr, regex) → hasHeader(xhr, name), using
getResponseHeader(name) !== null as the check. This is the exact check
the 12 call sites need, eliminates the substring-match class of bug, and
removes a layer of indirection (no more regex construction or
getAllResponseHeaders() scan per check).
Adds a regression test with X-HX-Trigger: foo that previously crashed
inside handleTriggerHeader.
Fixes #527. Addresses @1cg's suggestion in that thread.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>