Skip to content

Commit

Permalink
Correct spaze/sri-macros concatenations (#367)
Browse files Browse the repository at this point in the history
Check and make sure that spaze/sri-macros concatenated resources (e.g. `{script foo + bar}`) use spaces around the plus sign.

This is needed because in [Latte 3.0.17](https://github.com/nette/latte/releases/tag/v3.0.17), unquoted strings can contain `+` but if it's specified as ` + `, with spaces, then the previous behavior works too.

I've added tests in spaze/sri-macros#26, otherwise no change wasn't needed in that package.

Follow-up to #365
  • Loading branch information
spaze authored Jul 21, 2024
2 parents 4f6ae76 + 3479abd commit 1c4492a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions site/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/

Expand Down
2 changes: 1 addition & 1 deletion site/app/Admin/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 2 additions & 2 deletions site/app/Pulse/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{if isset($pageTitle)}{$pageTitle} | {/if}Pulse</title>
{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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>UPC Wi-Fi Keys{if isset($ssid)} for {$ssid}{/if}</title>
{styleSheet screen-upc}
{script app+upckeys async, defer}
{script app + upckeys async, defer}
{script remove-fbclid async, defer}
<meta property="og:image" content="{='upc/screenshot.jpg'|staticImageUrl}">
<meta property="og:title" content="UPC Wi-Fi Keys{if isset($ssid)} for {$ssid}{/if}">
Expand Down
6 changes: 3 additions & 3 deletions site/app/Www/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
<title>{if isset($pageTitle)}{$pageTitle} | {/if}Michal Špaček</title>
{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}
{ifset #preload}{include #preload}{/ifset}
{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}
Expand Down
2 changes: 1 addition & 1 deletion site/app/Www/Presenters/templates/Pgp/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
{/define}

{define #footerScripts}
{script openpgp+encryption id => "encryption-js"}
{script openpgp + encryption id => "encryption-js"}
{/define}
12 changes: 12 additions & 0 deletions site/bin/check-sri-macros-concat.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1c4492a

Please sign in to comment.