Encoding issue with Spotify Apps JavaScript functions

I'm having trouble with some JavaScript functions in Spotify Apps. When I try to use encodeURI, escape, or encodeURIComponent, the output looks weird. Check this out:

let artist = 'Coldplay';
console.log(escape(artist));
console.log(encodeURI(artist));
console.log(encodeURIComponent(artist));

The console shows 'Coldplay' for all three, but it should change the space to something else. This works fine in regular browsers.

Is this a known issue? Am I missing something? Where can we report Spotify Apps problems?

Update: Turns out the functions work correctly. The issue is when using alert() to display the result. It shows a messed up string even though the encoding is actually fine. Weird, right?

Hey there! I’ve been working with Spotify Apps for a while now, and I’ve definitely run into this encoding oddity before. It’s a real head-scratcher at first, but there’s a simple explanation.

The encoding functions are actually doing their job correctly. The problem lies in how Spotify’s environment displays the results. Here’s a neat trick I’ve found that helps:

Instead of using console.log or alert, try setting the encoded string as the text content of a DOM element. Something like:

document.getElementById(‘output’).textContent = encodeURIComponent(artist);

This way, you’ll see the properly encoded string. It’s not the most elegant solution, but it gets the job done.

As for reporting issues, the Spotify Developer Forum is your go-to place. They’re pretty good about addressing these quirks. Keep coding, and don’t let these little bumps discourage you!

I’ve encountered similar quirks when working with Spotify Apps. The encoding functions actually work as expected, but the console output can be misleading. Here’s a workaround I’ve found useful:

Instead of relying on console.log() or alert(), try using document.write() to display the encoded strings. This method seems to show the proper encoding.

let artist = ‘Coldplay’;
document.write(escape(artist) + ‘
’);
document.write(encodeURI(artist) + ‘
’);
document.write(encodeURIComponent(artist) + ‘
’);

This should display the correctly encoded strings. It’s a bit of a hassle, but it helps verify that the encoding is working correctly.

As for reporting issues, the Spotify Developer Forum is your best bet. They have a dedicated section for App-related problems where you can get support from both Spotify staff and other developers.

yo, i ran into this too. it’s a weird spotify thing. the functions work fine, but the output’s messed up. try using a different method to show the results, like document.write() or innerHTML. spotify’s dev forum is good for reporting these quirks. keep coding!

I’ve encountered this issue as well while developing Spotify Apps. It’s indeed a peculiar behavior specific to the Spotify environment. The encoding functions are actually working correctly, but the console output and alert() function don’t display the results accurately. To verify the proper encoding, you can try appending the encoded strings to the DOM or using a custom logging function. For instance:

function customLog(str) {
let div = document.createElement(‘div’);
div.textContent = str;
document.body.appendChild(div);
}

This approach should reveal that the encoding is functioning as expected. Regarding issue reporting, the Spotify Developer Forum is the primary channel for such concerns. They’re generally responsive to app-related problems and can provide further guidance if needed.