/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/configCases/html/script-src-sibling-attrs/test.js
28 строк
1 KB
Alexander Akait
fix(html): correct output.html.inject edge cases (#21416)
14 июл 2026, 17:14
Не верифицирован
14 июл 2026, 17:14
989d9eb
Код
Авторство
О чём код?
const fs = require("fs"); const path = require("path"); const readFile = (name) => fs.readFileSync(path.resolve(__dirname, name), "utf-8"); it("should copy quoted, bare and unquoted CSP/fetch attributes byte-exact onto the synthesized sibling <link>", () => { const extracted = readFile("page.html"); const linkMatch = extracted.match(/<link rel="stylesheet"[^>]*>/); expect(linkMatch).not.toBeNull(); const linkTag = linkMatch[0]; expect(linkTag).toMatch(/href="[^"]+\.css"/); // Each copyable attribute is carried back in its original source form — // quoted, bare (valueless), and unquoted — in the fixed nonce/crossorigin/ // referrerpolicy order, regardless of source order. expect(linkTag).toContain( ' nonce="tok-1" crossorigin referrerpolicy=origin' ); // `defer` is not a copyable attribute, so it must not leak onto the link. expect(linkTag).not.toContain("defer"); // The script is `defer`, so the link follows it (Vite order). const scriptIdx = extracted.indexOf("<script"); const linkIdx = extracted.indexOf('<link rel="stylesheet"'); expect(linkIdx).toBeGreaterThan(scriptIdx); });