Skip to content

Commit d18552f

Browse files
sstidlStefan Stidl
andauthored
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>
1 parent 03d62a0 commit d18552f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

docker/entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ is_alpine() {
1717
[ -f /etc/alpine-release ]
1818
}
1919

20+
html_escape() {
21+
printf '%s' "$1" | sed \
22+
-e 's/&/\&amp;/g' \
23+
-e 's/</\&lt;/g' \
24+
-e 's/>/\&gt;/g' \
25+
-e 's/"/\&quot;/g' \
26+
-e "s/'/\&#39;/g"
27+
}
28+
29+
sed_escape() {
30+
printf '%s\n' "$1" | sed 's/[&/\\]/\\&/g; s/\$/\\$/g'
31+
}
32+
2033
# Cleanup
2134
rm -rf /var/www/html/*
2235

@@ -84,6 +97,17 @@ if [[ "$MODE" == "frontend" || "$MODE" == "dual" || "$MODE" == "standalone" ]];
8497
sed -i "s/var SPEEDTEST_SERVERS = \"server-list.json\";/var SPEEDTEST_SERVERS = \"$SERVER_LIST_URL_ESCAPED\";/" /var/www/html/index-modern.html
8598
sed -i "s/var SPEEDTEST_SERVERS = \\[/var SPEEDTEST_SERVERS = \"$SERVER_LIST_URL_ESCAPED\";\\n\\t\\t\\/\\*/" /var/www/html/index-classic.html
8699
fi
100+
101+
# Replace title placeholders if TITLE is set
102+
if [ ! -z "$TITLE" ]; then
103+
TITLE_ONE_LINE=${TITLE//$'\r'/}
104+
TITLE_ONE_LINE=${TITLE_ONE_LINE//$'\n'/ }
105+
TITLE_HTML_ESCAPED=$(html_escape "$TITLE_ONE_LINE")
106+
TITLE_ESCAPED=$(sed_escape "$TITLE_HTML_ESCAPED")
107+
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
108+
sed -i "s/<title>LibreSpeed<\\/title>/<title>$TITLE_ESCAPED<\\/title>/g" /var/www/html/index.html
109+
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
110+
fi
87111

88112
# Support legacy EMAIL env var as fallback for GDPR_EMAIL
89113
if [ -z "$GDPR_EMAIL" ] && [ ! -z "$EMAIL" ]; then

tests/docker-compose-playwright.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
- MODE=standalone
2727
- WEBPORT=8080
2828
- USE_NEW_DESIGN=true
29+
- 'TITLE=Grüße "Tempo" ''Österreich'''
2930
ports:
3031
- "18185:8080"
3132

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { test, expect } = require('@playwright/test');
2+
const { baseUrls } = require('./helpers/env');
3+
4+
const specialTitle = 'Grüße "Tempo" \'Österreich\'';
5+
6+
test.describe('TITLE special characters', () => {
7+
test('modern page title supports umlauts and quotes', async ({ page }) => {
8+
await page.goto(`${baseUrls.standaloneNew}/index-modern.html`);
9+
await expect(page).toHaveTitle(`${specialTitle} - Free and Open Source Speedtest`);
10+
});
11+
12+
test('classic heading supports umlauts and quotes', async ({ page }) => {
13+
await page.goto(`${baseUrls.standaloneNew}/index-classic.html`);
14+
await expect(page.locator('h1').first()).toHaveText(specialTitle);
15+
});
16+
});

0 commit comments

Comments
 (0)