From fd0dcd858935acd57c44e91adf4a8313fd812bb8 Mon Sep 17 00:00:00 2001 From: Daniel Stratman Date: Thu, 23 Jun 2022 09:15:51 -0500 Subject: [PATCH] Update apply-csp.js (#139) Match cross-platform newline characters. --- _11ty/apply-csp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_11ty/apply-csp.js b/_11ty/apply-csp.js index 476dc62..65c44db 100644 --- a/_11ty/apply-csp.js +++ b/_11ty/apply-csp.js @@ -73,7 +73,7 @@ const addCspHash = async (rawContent, outputPath) => { const filePathPrettyURL = filePath.slice(0, -10); // blog/index.html -> /blog/ try { const headers = fs.readFileSync(headersPath, { encoding: "utf-8" }); - const regExp = /(# \[csp headers\]\n)([\s\S]*)(# \[end csp headers\])/; + const regExp = /(# \[csp headers\][\r\n]+)([\s\S]*)(# \[end csp headers\])/; const match = headers.match(regExp); if (!match) { throw `Check your _headers file. I couldn't find the text block for the csp headers: @@ -118,7 +118,7 @@ const addCspHash = async (rawContent, outputPath) => { function parseHeaders(headersFile) { let currentFilename; let headers = {}; - for (let line of headersFile.split(/\n+/)) { + for (let line of headersFile.split(/[\r\n]+/)) { if (!line) continue; if (/^\S/.test(line)) { currentFilename = line;