overleaf/services/web/bin/lint_pug_templates
Jakob Ackermann 535c97e8cf Merge pull request #3774 from overleaf/jpa-meta
[frontend] import meta tag processing from das7pads fork

GitOrigin-RevId: ca74ff9fbbcb51091a626a45468ff3d24d6136ca
2021-03-23 03:05:12 +00:00

31 lines
803 B
Bash
Executable file

#!/bin/sh
set -e
TEMPLATES_EXTENDING_META_BLOCK=$(\
grep \
--files-with-matches \
--recursive app/views modules/*/app/views \
--regex 'block append meta' \
--regex 'block prepend meta' \
--regex 'append meta' \
--regex 'prepend meta' \
)
for file in ${TEMPLATES_EXTENDING_META_BLOCK}; do
if ! grep "$file" --quiet --extended-regexp -e 'extends .+layout'; then
cat <<MSG >&2
ERROR: $file is a partial template and extends 'block meta'.
Using block append/prepend in a partial will duplicate the block contents into
the <body> due to a bug in pug.
Putting meta tags in the <body> can lead to Angular XSS.
You will need to refactor the partial and move the block into the top level
page template that extends the global layout.pug.
MSG
exit 1
fi
done