diff --git a/static/functions/lastfm.js b/static/functions/lastfm.js
index 59272dbf..1903ecf0 100644
--- a/static/functions/lastfm.js
+++ b/static/functions/lastfm.js
@@ -111,10 +111,15 @@
}
}
- // Escape ampersands with html code to avoid breaking the search links
- function escapeAmp(input){
+ // Escape ampersands with url code to avoid breaking the search links
+ function escapeAmpUrl(input){
return input.replace(/&/g,"%26");
}
+
+ // Escape ampersands with html code to avoid breaking the search links
+ function escapeAmpHtml(input){
+ return input.replace(/&/g,"&");
+ }
// Functions for fetching the required data are as follows.
@@ -166,11 +171,11 @@
var k = initialCount;
if (a.length < 3) k = a.length;
for (var i = 0; i < k; i++) {
- sharedArtistsHtml += '
' + a[i]['name'] + ''
+ sharedArtistsHtml += '' + escapeAmpHtml(a[i]['name']) + ''
}
if ( a.length > 3 ){
for (i = 3; i < a.length; i++) {
- sharedArtistsHtml += '' + a[i]['name'] + ''
+ sharedArtistsHtml += '' + escapeAmpHtml(a[i]['name']) + ''
}
sharedArtistsHtml += '[Expand]'
}
@@ -210,7 +215,7 @@
// Fix Last.fm API returning more than one entry despite limit on certain conditions.
if ( typeof(json[0]) === "object" ) json = json[0];
html += 'Last played: ';
- html += '' + json['artist']['#text'] + ' - ' + json['name'] + '';
+ html += '' + escapeAmpHtml(json['artist']['#text']) + ' - ' + escapeAmpHtml(json['name']) + '';
html += "";
lastPlayedTrack = html;
}
@@ -245,11 +250,11 @@
var k = initialCount;
if (j.length < 3) k = j.length;
for (var i = 0; i < k; i++) {
- html += '' + j[i]['name'] + ''
+ html += '' + escapeAmpHtml(j[i]['name']) + ''
}
if ( j.length>3 ){
for (i = 3; i < j.length; i++) {
- html += '' + j[i]['name'] + ''
+ html += '' + escapeAmpHtml(j[i]['name']) + ''
}
html+= '[Expand]'
}
@@ -288,11 +293,11 @@
var k = initialCount;
if (j.length < 3) k = j.length;
for (var i = 0; i < k; i++) {
- html += '' + j[i]['artist']['name'] + ' - ' + j[i]['name'] + ''
+ html += '' + escapeAmpHtml(j[i]['artist']['name']) + ' - ' + escapeAmpHtml(j[i]['name']) + ''
}
if ( j.length>3 ){
for (i = 3; i < j.length; i++) {
- html += '' + j[i]['artist']['name'] + ' - ' + j[i]['name'] + ''
+ html += '' + escapeAmpHtml(j[i]['artist']['name']) + ' - ' + escapeAmpHtml(j[i]['name']) + ''
}
html+= '[Expand]'
}
@@ -331,11 +336,11 @@
var k = initialCount;
if (j.length < 3) k = j.length;
for (var i = 0; i < k; i++) {
- html += '' + j[i]['artist']['name'] + ' - ' + j[i]['name'] + ''
+ html += '' + escapeAmpHtml(j[i]['artist']['name']) + ' - ' + escapeAmpHtml(j[i]['name']) + ''
}
if ( j.length>3 ){
for (i = 3; i < j.length; i++) {
- html += '' + j[i]['artist']['name'] + ' - ' + j[i]['name'] + ''
+ html += '' + escapeAmpHtml(j[i]['artist']['name']) + ' - ' + escapeAmpHtml(j[i]['name']) + ''
}
html+= '[Expand]'
}