Skip to content

Improper handling of $responseBody #19

@davegraham92120

Description

@davegraham92120

See script: HTTP BaseElements( {request} ).

The default handling of the response body for "other" content-types (see line 162) is:

Quote ( 
   Substitute ( 
     $responseBody ; 
     [ Char ( 8 ) ; "\b" ] ;
     [ Char ( 12 ) ; "\f" ] ; 
     [ "¶" ; "\n" ] ; 
     [ Char ( 13 ) ; "\r" ] ; 
     [ Char ( 9 ) ; "\t" ]
   ) 
)`

I'm not sure when there's a valid case to return the $responseBody quoted, but at least in this case it causes problems where the content-type is text/xml.

Sample $responseBody returned from API:

<?xml version="1.0" encoding="UTF-8"?><rsp stat="ok" version="1.0"> <api_key>asdfasdfasfda</api_key></rsp>

Note: there are multiple Char(10) characters that are not visible in the text (above).

Here's what it gets converted to:

"<?xml version=\"1.0\" encoding=\"UTF-8\"?><rsp stat=\"ok\" version=\"1.0\"> <api_key>kasjf;lskdfj;asldjk</api_key></rsp>"

When this gets added to the JSON object (line 177), the result is "?", and the custom function returns the following error: "SyntaxError: eof or line terminator while parsing string literal (line 3)."

I added another test at line 161 for a content-type of text/xml, with the following code:


Substitute ( $responseBody ; 
     [ Char ( 8 ) ; "\b" ] ;
     [ Char ( 12 ) ; "\f" ] ; 
     [ "¶" ; "\n" ] ; 
     [ Char ( 13 ) ; "\r" ] ; 
     [ Char ( 10 ) ; "\r" ] ; 
     [ Char ( 9 ) ; "\t" ]
 )

Note: this is almost the same as the code above, except it doesn't quote the result and also converts line feeds (i.e., Char ( 10 )).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions