Fix Map to Local button when artists array is empty

- Safely handle empty or undefined artists array
- Prevents 'expected expression, got }' JavaScript error
- Also fixed artists display to handle undefined arrays
This commit is contained in:
2026-02-03 19:55:30 -05:00
parent c7785b6488
commit a2a48f6ed9

View File

@@ -1618,7 +1618,9 @@
// Use JSON.stringify to properly escape strings for JavaScript
const escapedName = JSON.stringify(name);
const escapedTitle = JSON.stringify(t.title || '');
const escapedArtist = JSON.stringify((t.artists && t.artists[0]) || '');
// Safely get first artist, defaulting to empty string
const firstArtist = (t.artists && t.artists.length > 0) ? t.artists[0] : '';
const escapedArtist = JSON.stringify(firstArtist);
const escapedSpotifyId = JSON.stringify(t.spotifyId || '');
mapButton = `<button class="small" onclick="openManualMap(${escapedName}, ${t.position}, ${escapedTitle}, ${escapedArtist}, ${escapedSpotifyId})" style="margin-left:8px;font-size:0.75rem;padding:4px 8px;">Map to Local</button>`;
}
@@ -1628,7 +1630,7 @@
<span class="track-position">${t.position + 1}</span>
<div class="track-info">
<h4>${escapeHtml(t.title)}${statusBadge}${mapButton}</h4>
<span class="artists">${escapeHtml(t.artists.join(', '))}</span>
<span class="artists">${escapeHtml((t.artists || []).join(', '))}</span>
</div>
<div class="track-meta">
${t.album ? escapeHtml(t.album) : ''}