From 2d04968be06319b8ec4b39b57ce4ef793419d6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0pa=C4=8Dek?= Date: Sun, 21 Jul 2024 23:00:27 +0200 Subject: [PATCH 1/2] Check that spaze/sri-macros concatenated resources use spaces around the plus sign This is needed because in Latte 3.0.17, unquoted strings can contain "+" but if it's specified as " + ", with spaces, then the previous behavior works too. https://github.com/nette/latte/releases/tag/v3.0.17 I've added tests to spaze/sri-macros, otherwise no change wasn't needed in that package. https://github.com/spaze/sri-macros/pull/26 --- site/app/Admin/Presenters/templates/@layout.latte | 2 +- site/app/Pulse/Presenters/templates/@layout.latte | 4 ++-- .../app/UpcKeys/Presenters/templates/Homepage/default.latte | 2 +- site/app/Www/Presenters/templates/@layout.latte | 6 +++--- site/app/Www/Presenters/templates/Pgp/default.latte | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/site/app/Admin/Presenters/templates/@layout.latte b/site/app/Admin/Presenters/templates/@layout.latte index d6265b630..13c3fd866 100644 --- a/site/app/Admin/Presenters/templates/@layout.latte +++ b/site/app/Admin/Presenters/templates/@layout.latte @@ -4,6 +4,6 @@ {var $robots = 'noindex, nofollow'} {define #feeds}{/define} {define #scriptsReplace} -{script app+admin async, defer} +{script app + admin async, defer} {script netteForms async, defer} {/define} diff --git a/site/app/Pulse/Presenters/templates/@layout.latte b/site/app/Pulse/Presenters/templates/@layout.latte index 78182fcfa..7b0ce1d0c 100644 --- a/site/app/Pulse/Presenters/templates/@layout.latte +++ b/site/app/Pulse/Presenters/templates/@layout.latte @@ -6,8 +6,8 @@ {if isset($pageTitle)}{$pageTitle} | {/if}Pulse {control criticalCss} - {styleSheet screen-pulse+rating} - {script app+pulse async, defer} + {styleSheet screen-pulse + rating} + {script app + pulse async, defer} {script remove-fbclid async, defer} {ifset #metas}{include #metas}{/ifset} {ifset $canonicalLink} diff --git a/site/app/UpcKeys/Presenters/templates/Homepage/default.latte b/site/app/UpcKeys/Presenters/templates/Homepage/default.latte index d67d3921b..66bb57d29 100644 --- a/site/app/UpcKeys/Presenters/templates/Homepage/default.latte +++ b/site/app/UpcKeys/Presenters/templates/Homepage/default.latte @@ -6,7 +6,7 @@ UPC Wi-Fi Keys{if isset($ssid)} for {$ssid}{/if} {styleSheet screen-upc} - {script app+upckeys async, defer} + {script app + upckeys async, defer} {script remove-fbclid async, defer} diff --git a/site/app/Www/Presenters/templates/@layout.latte b/site/app/Www/Presenters/templates/@layout.latte index 1dcf6871e..2f1c163da 100644 --- a/site/app/Www/Presenters/templates/@layout.latte +++ b/site/app/Www/Presenters/templates/@layout.latte @@ -13,9 +13,9 @@ {if isset($pageTitle)}{$pageTitle} | {/if}Michal Špaček {control criticalCss} {if $darkMode === null} - {styleSheet screen-main+'@media (prefers-color-scheme: dark) {'+screen-main-dark+'}'} + {styleSheet screen-main + '@media (prefers-color-scheme: dark) {' + screen-main-dark + '}'} {elseif $darkMode} - {styleSheet screen-main+screen-main-dark} + {styleSheet screen-main + screen-main-dark} {else} {styleSheet screen-main} {/if} @@ -23,7 +23,7 @@ {ifset #scriptsReplace} {include #scriptsReplace} {else} - {script app+scripts async, defer} + {script app + scripts async, defer} {script netteForms async, defer} {script remove-fbclid async, defer} {/ifset} diff --git a/site/app/Www/Presenters/templates/Pgp/default.latte b/site/app/Www/Presenters/templates/Pgp/default.latte index 1a27d413f..65774d60b 100644 --- a/site/app/Www/Presenters/templates/Pgp/default.latte +++ b/site/app/Www/Presenters/templates/Pgp/default.latte @@ -32,5 +32,5 @@ {/define} {define #footerScripts} - {script openpgp+encryption id => "encryption-js"} + {script openpgp + encryption id => "encryption-js"} {/define} From 3479abd8a5c0e79bf7c4cabd1795af61588ba1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0pa=C4=8Dek?= Date: Sun, 21 Jul 2024 23:03:51 +0200 Subject: [PATCH 2/2] Test all concats are okay --- .github/workflows/php.yml | 6 ++++++ site/Makefile | 7 +++++-- site/bin/check-sri-macros-concat.sh | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100755 site/bin/check-sri-macros-concat.sh diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6d737e8ed..dcb9edf66 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -76,6 +76,12 @@ jobs: php-version: ${{ matrix.php-version }} - run: make --directory=site check-application-mapping + check-sri-macros-concat: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - run: make --directory=site check-sri-macros-concat + lint-php: runs-on: ubuntu-latest strategy: diff --git a/site/Makefile b/site/Makefile index 859702055..500c7ff20 100644 --- a/site/Makefile +++ b/site/Makefile @@ -1,6 +1,6 @@ -.PHONY: test composer-audit npm-audit cs-fix check-file-patterns check-makefile check-application-mapping lint-php lint-latte lint-neon lint-xml lint-xml-auto-install phpcs phpstan phpstan-latte-templates phpstan-vendor psalm tester tester-include-skipped gitleaks composer-dependency-analyser +.PHONY: test composer-audit npm-audit cs-fix check-file-patterns check-makefile check-application-mapping check-sri-macros-concat lint-php lint-latte lint-neon lint-xml lint-xml-auto-install phpcs phpstan phpstan-latte-templates phpstan-vendor psalm tester tester-include-skipped gitleaks composer-dependency-analyser -test: composer-audit npm-audit check-file-patterns check-makefile check-application-mapping lint-php lint-latte lint-neon lint-xml phpcs phpstan tester psalm phpstan-vendor composer-dependency-analyser +test: composer-audit npm-audit check-file-patterns check-makefile check-application-mapping check-sri-macros-concat lint-php lint-latte lint-neon lint-xml phpcs phpstan tester psalm phpstan-vendor composer-dependency-analyser composer-audit: composer audit @@ -20,6 +20,9 @@ check-makefile: check-application-mapping: bin/check-application-mapping.php +check-sri-macros-concat: + bin/check-sri-macros-concat.sh + lint-php: vendor/php-parallel-lint/php-parallel-lint/parallel-lint --colors -e php,phtml,phpt,phpstub app/ public/ stubs/ tests/ diff --git a/site/bin/check-sri-macros-concat.sh b/site/bin/check-sri-macros-concat.sh new file mode 100755 index 000000000..ca8d7a754 --- /dev/null +++ b/site/bin/check-sri-macros-concat.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +echo "Wrong spaze/sri-macros concatenations (without spaces, e.g. {script foo+bar}):" + +BAD_LINES=$(grep --recursive --perl-regexp --ignore-case --line-number "{(script|stylesheet)" app/ | grep --perl-regexp "[^\s]\+|\+[^\s]") +if [ "$BAD_LINES" ]; then + echo "$BAD_LINES" | grep --color ".+." + exit 1 +else + echo "None, all have spaces around the plus sign (foo + bar, not foo+bar)" + exit 0 +fi