(tagSource: string, attr: string)
| 123 | } |
| 124 | |
| 125 | export function readAttr(tagSource: string, attr: string): string | null { |
| 126 | if (!tagSource) return null; |
| 127 | const escaped = attr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
| 128 | // `(?<![\w-])` not `\b`: a plain `\b` boundary treats the hyphen in a longer |
| 129 | // attribute as a word break, so reading "id" would wrongly match the trailing |
| 130 | // `id="…"` inside `data-hf-id="…"` (and "width" inside `data-width`, etc.). |
| 131 | // The lookbehind requires the match to start a fresh attribute name. |
| 132 | const match = tagSource.match(new RegExp(`(?<![\\w-])${escaped}\\s*=\\s*["']([^"']+)["']`, "i")); |
| 133 | return match?.[1] || null; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Read an attribute that may legitimately contain the opposite quote |
no outgoing calls
no test coverage detected