From 2cb9388d6ced5b0b7498573c399f911d87c8d852 Mon Sep 17 00:00:00 2001
From: STARSCrazy <stars_crazy@gmx.de>
Date: Fri, 7 Jan 2022 19:29:09 +0100
Subject: [PATCH] Update spotify-web-api.js

Corrects the issue with the encoded "+" in the search request.
---
 src/spotify-web-api.js | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/spotify-web-api.js b/src/spotify-web-api.js
index c73ad58..908737f 100644
--- a/src/spotify-web-api.js
+++ b/src/spotify-web-api.js
@@ -55,12 +55,16 @@ var SpotifyWebApi = (function () {
     return target;
   };
 
-  var _buildUrl = function (url, parameters) {
+  var _buildUrl = function (url, parameters, dontEncodePlus) {
     var qs = '';
     for (var key in parameters) {
       if (parameters.hasOwnProperty(key)) {
         var value = parameters[key];
-        qs += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&';
+        if (dontEncodePlus) {        
+            qs += encodeURIComponent(key) + '=' + value.split('+').map(x => encodeURIComponent(x)).join('+') + '&';
+        } else {
+            qs += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&';
+        }
       }
     }
     if (qs.length > 0) {
@@ -94,7 +98,7 @@ var SpotifyWebApi = (function () {
       }
 
       var type = requestData.type || 'GET';
-      req.open(type, _buildUrl(requestData.url, requestData.params));
+      req.open(type, _buildUrl(requestData.url, requestData.params, requestData.dontEncodePlus));
       if (_accessToken) {
         req.setRequestHeader('Authorization', 'Bearer ' + _accessToken);
       }
@@ -1360,7 +1364,8 @@ var SpotifyWebApi = (function () {
       params: {
         q: query,
         type: types.join(',')
-      }
+      },
+      dontEncodePlus: true
     };
     return _checkParamsAndPerformRequest(requestData, options, callback);
   };