lua-users home
lua-l archive

Re: Reporting possible BUG on string.gsub

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


> please take a look at the following code:
> 
> ----BEGIN---
> str = [[This is a string with @@ANYTHING@@ chance of survival]];
> replace = "5%"
> print(str)
> print(replace)
> str = str:gsub("@@ANYTHING@@", replace)
> print(str)
> -----END----
> 
> The result I have here is
> ----BEGIN---
> This is a string with @@ANYTHING@@ chance of survival
> 5%
> This is a string with 5
> -----END----
> 
> But the last sentence should be "This is a string with 5% chance of
> survival".
Actually, the last sentence is not what you are seeing, and it should not
be what you said. The last sentence is actually
 This is a string with 50円 chance of survival
The '%' is an escape in the replacement string too. It should be followed
by some character. As it is not, Lua is using the terminating 0 instead.
It would be nicer if Lua raised an error in this case, but I am not sure
this is a bug: it simply follows the rule garbage in -> garbage out.
> Do I get to have my name on http://www.lua.org/bugs.html??
Maybe ;)
-- Roberto

AltStyle によって変換されたページ (->オリジナル) /