diff --git a/tests/station-sharing-mailto-line-endings.test.mjs b/tests/station-sharing-mailto-line-endings.test.mjs index e6852fb8..028d6440 100644 --- a/tests/station-sharing-mailto-line-endings.test.mjs +++ b/tests/station-sharing-mailto-line-endings.test.mjs @@ -19,3 +19,18 @@ test('mailto body normalizes mixed CRLF, CR and LF to single CRLF', () => { assert.equal((body.match(/\r\n/g) || []).length, 6); assert.equal(body.replace(/\r\n/g, '').includes('\r'), false); }); + + +test('mailto expands a single localized placeholder without leaking literal braces or duplicating station details', () => { + const stationOnly = new URL(stationReportEmailUrl( + '/vn/ho-chi-minh/test-radio', 'Test Radio', 'Playback problem', 'Station: {station}', + )); + const urlOnly = new URL(stationReportEmailUrl( + '/vn/ho-chi-minh/test-radio', 'Test Radio', 'Playback problem', 'Station page: {url}', + )); + const stationBody = stationOnly.searchParams.get('body'); + const urlBody = urlOnly.searchParams.get('body'); + assert.equal(stationBody, 'Station: Test Radio\r\nhttps://radio.eplus.dev/vn/ho-chi-minh/test-radio'); + assert.equal(urlBody, 'Station page: https://radio.eplus.dev/vn/ho-chi-minh/test-radio\r\nTest Radio'); + assert.doesNotMatch(stationBody + urlBody, /\{(?:station|url)\}/); +}); diff --git a/utils/station-sharing.mjs b/utils/station-sharing.mjs index ab892a92..b049a28c 100644 --- a/utils/station-sharing.mjs +++ b/utils/station-sharing.mjs @@ -49,9 +49,11 @@ export function stationReportEmailUrl(path, title, subject, description) { const message = String(description || 'I cannot hear this station.').slice(0, 1000); // Localized templates may place the station name and public URL directly in // the email. Preserve the previous plain-text fallback for older callers. - const hasPlaceholders = message.includes('{station}') && message.includes('{url}'); + const hasPlaceholders = /\{(?:station|url)\}/.test(message); const body = hasPlaceholders ? message.replace(/\{(station|url)\}/g, (_match, key) => key === 'station' ? safeTitle : stationPage) + + (message.includes('{station}') ? '' : '\n' + safeTitle) + + (message.includes('{url}') ? '' : '\n' + stationPage) : message + '\n\n' + safeTitle + '\n' + stationPage; // mailto URLs follow RFC 6068, not HTML form encoding. URLSearchParams