Forum Discussion

mpw83's avatar
mpw83
Contributor
6 years ago

Getting 'Malformed escape pair' for '%' in query parameter


I am trying to filter some Id's in my query using Like '%Collections%' . I am sure the SQL is correct and working. But in SoapUI request I am getting `Malformed escape pair at index 202:`. Seems it does not like `%` character. Is there any way to solve this issue? help much appreciated. 

  • Hi mpw83 

     

    I'm such an idiot sometimes - you told me the problem - I really dont know what I was thinking.  

     

    Its the percent encoding - you are using the SQL wildcard % in your query - but % is a reserved character in HTTP - so you can't just use it like you have (this is why quite often when representing SQL query hits like this, RESTful requests replace the % wildcard with an alternative so this isn't a problem

     

    Anyway - if you go into Projects and view either the method or resource - click on any parameter (header, query, template) to enable the functionality - at the bottom there is a checkbox that relates to disabling the URL/percent encoding.  I've never used this before but I suspect this will do what you need so ReadyAPI! doesn't trap your request - see the following screenshot

    An An alternative to disabling the percent encoding is to escape the % char in yoru request.

     

    %'s escape sequence is %25 - so if you replace '%Collections%' with '%25Collections%25' that should work.

     

    I encoded your whole URI query string - so 

     

    q=select+id+from+loan__Bank_Account__c+where+loan_ffa__Payment_Mode__c+=+'a5C90000000YaLxEAK'+and+loan__Bank_Name__c+LIKE+'%Collection%'

    encodes as the following:

     

    q%3Dselect%2Bid%2Bfrom%2Bloan__Bank_Account__c%2Bwhere%2Bloan_ffa__Payment_Mode__c%2B%3D%2B%27a5C90000000YaLxEAK%27%2Band%2Bloan__Bank_Name__c%2BLIKE%2B%27%25Collection%25%27

     

    Hope this helps,

     

    cheers,

     

    rich

     

     

  • richie's avatar
    richie
    Community Hero

    Hi mpw83 

     

    can you show me the RAW of your request once submitted please?

     

    I would expect the URI to be percent encoding so I'm curious as to whether this is being converted properly.

     

    Also - it would help to diagnose your issue if you could provide the URI pattern of the query string so we can see what attributes are allowed/not allowed

     

    ta

     

    rich

     

    • mpw83's avatar
      mpw83
      Contributor

      richie , Thanks for your reply. Because the request is not submitting due to this "MALFORMED_QUERY" issue the raw request is similar to as follows, 

      GET https://localhost:8080/services/data/v39.0/queryAll/ HTTP/1.1
      Accept-Encoding: gzip,deflate
      Authorization: OAuth 00D0p0000000SLb!AQIAQLzs22Oa1qL8Hl6NsTHdlEq5aFPFFTsdEVTOnzwUJ.MCpSgF.33MBHvfL1lenIvNTkPI.jCqz9vEpFcmcQyVJsBWRvd1
      Content-Length: 0
      Host: localhost
      Connection: Keep-Alive
      User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_181)
      

      the query that I am trying to execute is  

       

      http:localhost:8080/services/data/v39.0/queryAll/?q=select+id+from+loan__Bank_Account__c+where+loan_ffa__Payment_Mode__c+=+'a5C90000000YaLxEAK'+and+loan__Bank_Name__c+LIKE+'%Collection%'
      • richie's avatar
        richie
        Community Hero

        Hi mpw83 

         

        I'm such an idiot sometimes - you told me the problem - I really dont know what I was thinking.  

         

        Its the percent encoding - you are using the SQL wildcard % in your query - but % is a reserved character in HTTP - so you can't just use it like you have (this is why quite often when representing SQL query hits like this, RESTful requests replace the % wildcard with an alternative so this isn't a problem

         

        Anyway - if you go into Projects and view either the method or resource - click on any parameter (header, query, template) to enable the functionality - at the bottom there is a checkbox that relates to disabling the URL/percent encoding.  I've never used this before but I suspect this will do what you need so ReadyAPI! doesn't trap your request - see the following screenshot

        An An alternative to disabling the percent encoding is to escape the % char in yoru request.

         

        %'s escape sequence is %25 - so if you replace '%Collections%' with '%25Collections%25' that should work.

         

        I encoded your whole URI query string - so 

         

        q=select+id+from+loan__Bank_Account__c+where+loan_ffa__Payment_Mode__c+=+'a5C90000000YaLxEAK'+and+loan__Bank_Name__c+LIKE+'%Collection%'

        encodes as the following:

         

        q%3Dselect%2Bid%2Bfrom%2Bloan__Bank_Account__c%2Bwhere%2Bloan_ffa__Payment_Mode__c%2B%3D%2B%27a5C90000000YaLxEAK%27%2Band%2Bloan__Bank_Name__c%2BLIKE%2B%27%25Collection%25%27

         

        Hope this helps,

         

        cheers,

         

        rich