string.format("%q",s) bug?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

string.format("%q",s) bug?

Adam D. Moss
Hi there.
If I %q-format a string with \r in it, the \r gets entered into the
string literally and the Lua interpreter barfs reading it back,
contrary to the documentation.  This is Lua5.1 (LuaJIT 1.1.0).
Bug or my problem?
Cheers,
--adam
Reply | Threaded
Open this post in threaded view
|

Re: string.format("%q",s) bug?

D Burgess-4
On which OS?
Reply | Threaded
Open this post in threaded view
|

Re: string.format("%q",s) bug?

Adam D. Moss
D Burgess wrote:
> On which OS?

Linux.

Reply | Threaded
Open this post in threaded view
|

Re: string.format("%q",s) bug?

Luiz Henrique de Figueiredo
In reply to this post by Adam D. Moss
> If I %q-format a string with \r in it, the \r gets entered into the
> string literally and the Lua interpreter barfs reading it back,
> contrary to the documentation.  This is Lua5.1 (LuaJIT 1.1.0).
> Bug or my problem?

This is a bug, sorry. Here is a fix:

***************
*** 703,708 ****
--- 703,712 ----
          luaL_addchar(b, *s);
          break;
        }
+       case '\r': {
+         luaL_addlstring(b, "\\r", 2);
+         break;
+       }
        case '\0': {
          luaL_addlstring(b, "\\000", 4);
          break;
Reply | Threaded
Open this post in threaded view
|

Re: string.format("%q",s) bug?

Adam D. Moss
Luiz Henrique de Figueiredo wrote:
>> If I %q-format a string with \r in it, the \r gets entered into the
>> string literally and the Lua interpreter barfs reading it back,
>> contrary to the documentation.  This is Lua5.1 (LuaJIT 1.1.0).
>> Bug or my problem?
>
> This is a bug, sorry. Here is a fix:

Thanks!

--adam