docker: restore TITLE env handling in entrypoint (#787)

* docker: restore TITLE env handling in entrypoint

* docker: escape TITLE for HTML output

* test(e2e): cover TITLE with umlauts and quotes

---------

Co-authored-by: Stefan Stidl <sti-github@stidl.com>
This commit is contained in:
sstidl 2026-04-14 09:06:03 +02:00 committed by GitHub
parent 03d62a0ca1
commit d18552fe8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -17,6 +17,19 @@ is_alpine() {
[ -f /etc/alpine-release ]
}
html_escape() {
printf '%s' "$1" | sed \
-e 's/&/\&amp;/g' \
-e 's/</\&lt;/g' \
-e 's/>/\&gt;/g' \
-e 's/"/\&quot;/g' \
-e "s/'/\&#39;/g"
}
sed_escape() {
printf '%s\n' "$1" | sed 's/[&/\\]/\\&/g; s/\$/\\$/g'
}
# Cleanup
rm -rf /var/www/html/*
@ -84,6 +97,17 @@ if [[ "$MODE" == "frontend" || "$MODE" == "dual" || "$MODE" == "standalone" ]];
sed -i "s/var SPEEDTEST_SERVERS = \"server-list.json\";/var SPEEDTEST_SERVERS = \"$SERVER_LIST_URL_ESCAPED\";/" /var/www/html/index-modern.html
sed -i "s/var SPEEDTEST_SERVERS = \\[/var SPEEDTEST_SERVERS = \"$SERVER_LIST_URL_ESCAPED\";\\n\\t\\t\\/\\*/" /var/www/html/index-classic.html
fi
# Replace title placeholders if TITLE is set
if [ ! -z "$TITLE" ]; then
TITLE_ONE_LINE=${TITLE//$'\r'/}
TITLE_ONE_LINE=${TITLE_ONE_LINE//$'\n'/ }
TITLE_HTML_ESCAPED=$(html_escape "$TITLE_ONE_LINE")
TITLE_ESCAPED=$(sed_escape "$TITLE_HTML_ESCAPED")
sed -i "s/<title>LibreSpeed<\\/title>/<title>$TITLE_ESCAPED<\\/title>/g; s/<h1>LibreSpeed<\\/h1>/<h1>$TITLE_ESCAPED<\\/h1>/g" /var/www/html/index-classic.html
sed -i "s/<title>LibreSpeed<\\/title>/<title>$TITLE_ESCAPED<\\/title>/g" /var/www/html/index.html
sed -i "s/<title>LibreSpeed - Free and Open Source Speedtest<\\/title>/<title>$TITLE_ESCAPED - Free and Open Source Speedtest<\\/title>/g" /var/www/html/index-modern.html
fi
# Support legacy EMAIL env var as fallback for GDPR_EMAIL
if [ -z "$GDPR_EMAIL" ] && [ ! -z "$EMAIL" ]; then

View file

@ -26,6 +26,7 @@ services:
- MODE=standalone
- WEBPORT=8080
- USE_NEW_DESIGN=true
- 'TITLE=Grüße "Tempo" ''Österreich'''
ports:
- "18185:8080"

View file

@ -0,0 +1,16 @@
const { test, expect } = require('@playwright/test');
const { baseUrls } = require('./helpers/env');
const specialTitle = 'Grüße "Tempo" \'Österreich\'';
test.describe('TITLE special characters', () => {
test('modern page title supports umlauts and quotes', async ({ page }) => {
await page.goto(`${baseUrls.standaloneNew}/index-modern.html`);
await expect(page).toHaveTitle(`${specialTitle} - Free and Open Source Speedtest`);
});
test('classic heading supports umlauts and quotes', async ({ page }) => {
await page.goto(`${baseUrls.standaloneNew}/index-classic.html`);
await expect(page.locator('h1').first()).toHaveText(specialTitle);
});
});