ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-core

MFPRequest Crashes When Passed String With Spaces

Closed this issue · 1 comments

Parsing this from a support ticket. Any comments I can relay to the customer are appreciated.

In short it would appear that the customer would like to be able to pass MFPRequest a string with spaces (such as "iphone SE") and have the SDK code handle the replacement of the spaces with '%20' before attempting the request on the URL rather than placing the burden on the user.

Consider the code

var keywords = "iphone SE";
var request = new MFPRequest("/twitter/search/"+keywords,
MFPRequest.GET);
request.send("",
          function(successResponse){
                  console.log("response for success::
" + JSON.stringify(successResponse));
          },
          function (failureResponse){
                 console.log("error");
          }
);

Currently the above code would result in a crash with the exception 'NSInternalInconsistencyException',
reason: 'Invalid parameter not satisfying: url'

Thank you

aal80 commented

Hi James,

JavaScript provides encodedURI and encodedURIComponent APIs to easily achieve the required functionality. Instead of

var request = new MFPRequest("/twitter/search/"+key, MFPRequest.GET);

you can use

var requestUrl = encodeURI("/twitter/search/"+key);
var request = new MFPRequest(requestUrl, MFPRequest.GET);