proofgeist / generator

Generator - Store, explore, share and create FileMaker Code
MIT License
35 stars 8 forks source link

Improper handling of $responseBody #19

Open davegraham92120 opened 7 years ago

davegraham92120 commented 7 years ago

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 commented 7 years ago

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.