Commit 7389e03
fix: prevent partial response-header match TypeError (#527)
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>1 parent d53932d commit 7389e03
2 files changed
Lines changed: 31 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4039 | 4039 | | |
4040 | 4040 | | |
4041 | 4041 | | |
4042 | | - | |
| 4042 | + | |
4043 | 4043 | | |
4044 | 4044 | | |
4045 | | - | |
4046 | | - | |
| 4045 | + | |
| 4046 | + | |
4047 | 4047 | | |
4048 | 4048 | | |
4049 | 4049 | | |
| |||
4668 | 4668 | | |
4669 | 4669 | | |
4670 | 4670 | | |
4671 | | - | |
| 4671 | + | |
4672 | 4672 | | |
4673 | 4673 | | |
4674 | | - | |
| 4674 | + | |
4675 | 4675 | | |
4676 | 4676 | | |
4677 | | - | |
| 4677 | + | |
4678 | 4678 | | |
4679 | 4679 | | |
4680 | 4680 | | |
| |||
4809 | 4809 | | |
4810 | 4810 | | |
4811 | 4811 | | |
4812 | | - | |
| 4812 | + | |
4813 | 4813 | | |
4814 | 4814 | | |
4815 | 4815 | | |
4816 | | - | |
| 4816 | + | |
4817 | 4817 | | |
4818 | 4818 | | |
4819 | 4819 | | |
| |||
4828 | 4828 | | |
4829 | 4829 | | |
4830 | 4830 | | |
4831 | | - | |
| 4831 | + | |
4832 | 4832 | | |
4833 | | - | |
| 4833 | + | |
4834 | 4834 | | |
4835 | 4835 | | |
4836 | 4836 | | |
| |||
4859 | 4859 | | |
4860 | 4860 | | |
4861 | 4861 | | |
4862 | | - | |
| 4862 | + | |
4863 | 4863 | | |
4864 | 4864 | | |
4865 | 4865 | | |
4866 | | - | |
| 4866 | + | |
4867 | 4867 | | |
4868 | 4868 | | |
4869 | 4869 | | |
| |||
4919 | 4919 | | |
4920 | 4920 | | |
4921 | 4921 | | |
4922 | | - | |
| 4922 | + | |
4923 | 4923 | | |
4924 | 4924 | | |
4925 | 4925 | | |
| |||
4933 | 4933 | | |
4934 | 4934 | | |
4935 | 4935 | | |
4936 | | - | |
| 4936 | + | |
4937 | 4937 | | |
4938 | 4938 | | |
4939 | 4939 | | |
| |||
4942 | 4942 | | |
4943 | 4943 | | |
4944 | 4944 | | |
4945 | | - | |
| 4945 | + | |
4946 | 4946 | | |
4947 | 4947 | | |
4948 | 4948 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
536 | 552 | | |
0 commit comments