Skip to content

Commit

Permalink
Update apply-csp.js (#139)
Browse files Browse the repository at this point in the history
Match cross-platform newline characters.
  • Loading branch information
dastratman committed Jun 23, 2022
1 parent 835ee34 commit fd0dcd8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _11ty/apply-csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fd0dcd8

Please sign in to comment.