lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Laurent FAILLIE once stated:
> Hello,
> 
> How to encode an argument that contains an ampersand ?
> 
> My code is the following :
> 
>  client.call {
>         url = rendez_vous,
>         soapaction = "nanaafoutre",
>         method = "Report",
>         entries = {
>             {
>                     tag="status",
>                     attr = { "xsi:type", ["xsi:type"] = "xsd:boolean", },
>                     rc == 0 and "true" or "false"
>                 },{
>                     tag="output",
>                     attr = { "xsi:type", ["xsi:type"] = "xsd:string", },
>                     res
>                 }
>             }
>     }
>  
> but evrytime the string res contains "&" character, I got following error :
> 
> lua: /usr/local/share/lua/5.1/soap/client.lua:78: Error on request: 1
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Bad Request</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
> 
> So what have I to do ?

  This is less a Lua issue and more of an XML issue, but the answer is:  any
time you want to encode "&" in an XML document (and SOAP is encoded in XML)
you need to convert it to "&amp;".  

  An easy way to do that is

	res = res:gsub("%&","&amp;")

  A better way is to see of the library you are using can encode strings for
XML and use that.

  -spc (As there are some other characters you may need to watch out for)