Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ is_alpine() {
[ -f /etc/alpine-release ]
}

html_escape() {
printf '%s' "$1" | sed \
-e 's/&/\&/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/*

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/docker-compose-playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
- MODE=standalone
- WEBPORT=8080
- USE_NEW_DESIGN=true
- 'TITLE=Grüße "Tempo" ''Österreich'''
ports:
- "18185:8080"

Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/title-special-chars.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading