Commit bc03a5a
committed
fix(signal-processing): don't rewrite <body in script/style content
The body-tag auto-annotation pass (`<body([^>]*)>` → `<body$1
data-stx-auto>`) ran a global-but-first-match regex over the entire
rendered output. If any embedded `<script>` block contained a regex
literal like `/<body[^>]*>/` (common in HTML-cleaning libraries —
ts-medium-editor's paste extension does exactly this), the rewrite
landed inside the JS code instead of the document body.
The corrupted output looked like
[/^[\s\S]*<body[^ data-stx-auto>]*>\s*|.../g, ""]
which JS rejects with `Invalid regular expression: Range out of
order in character class` (the `-` chars inside `data-stx-auto`
become broken character ranges like `t-s`). The page-level script
fails to load, scopes don't register, downstream components don't
hydrate.
Two changes:
- Detect the body tag using a script/style-stripped copy of the
output, so embedded JS regex literals don't masquerade as a
body tag.
- When the rewrite is warranted, locate the actual body offset in
the original output by scanning past every <script>/<style>
block, and only rewrite at that anchored position.1 parent 89e233f commit bc03a5a
1 file changed
Lines changed: 35 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
953 | 953 | | |
954 | 954 | | |
955 | 955 | | |
956 | | - | |
957 | | - | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
958 | 963 | | |
959 | 964 | | |
960 | | - | |
961 | | - | |
962 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
963 | 993 | | |
964 | 994 | | |
965 | 995 | | |
| |||
0 commit comments