Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper handling of $responseBody #19

Open
davegraham92120 opened this issue May 25, 2017 · 1 comment
Open

Improper handling of $responseBody #19

davegraham92120 opened this issue May 25, 2017 · 1 comment

Comments

@davegraham92120
Copy link

davegraham92120 commented May 25, 2017

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 )).

@toddgeist
Copy link
Contributor

toddgeist commented May 25, 2017

The quoting thing is an escape hatch. There are strange edge cases where you might need it. Generator is optimized for use with JSON. XML and form-data SHOULD get built out, but almost no work has been done with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants