nginxbeautifier
nginxbeautifier copied to clipboard
Crash on multiline strings
When parsing a multiline string like this
add_header X-Content-Security-Policy "default-src 'self'; \
script-src 'self' https://ssl.google-analytics.com; \
img-src 'self' https://ssl.google-analytics.com";
nginxbeautifier crashes with a following error:
/opt/homebrew/lib/node_modules/nginxbeautifier/nginxbeautifier.js:142
return input.match(catchRegex)[1];
^
TypeError: Cannot read property '1' of null
at extractTextBySeperator (/opt/homebrew/lib/node_modules/nginxbeautifier/nginxbeautifier.js:142:39)
at extractAllPossibleText (/opt/homebrew/lib/node_modules/nginxbeautifier/nginxbeautifier.js:164:29)
at strip_line (/opt/homebrew/lib/node_modules/nginxbeautifier/nginxbeautifier.js:193:35)
at Object.clean_lines (/opt/homebrew/lib/node_modules/nginxbeautifier/nginxbeautifier.js:217:49)
at Object.<anonymous> (/opt/homebrew/lib/node_modules/nginxbeautifier/index.js:235:38)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
The workaround is to concatenate the string onto a long line:
add_header X-Content-Security-Policy "default-src 'self'; script-src 'self' https://ssl.google-analytics.com; img-src 'self' https://ssl.google-analytics.com";