On Mon, Jan 31, 2011 at 04:54:42AM +0100, Adrian C. wrote:
> It's a bug with gsub usage in helpers.lua, format function. The dash "-" 
> should be escaped at the time substitution happens. Example:
> 
> foo = "{/media/sam2-ntfs avail_p}"
> bar = 99
> format = "${/media/sam2-ntfs avail_p}"
> 
> print(format:gsub("$" .. foo, bar))
> ${/media/sam2-ntfs avail_p}   0
> 
> 
> foo = "{/media/sam2%-ntfs avail_p}"
> print(format:gsub("$" .. foo, bar))
> 99    1
> 
> 
> What is sensible to do in the code?
> 
> format = format:gsub("$" .. foo:gsub("-", "%%-"), bar)
> ...
> return format
> 
> I f* hate the idea of doing that extra substitution step. Psychon help!
> 
> -- 
> Adrian C. (anrxc) | anrxc..sysphere.org | PGP ID: D20A0618
> PGP FP: 02A5 628A D8EE 2A93 996E  929F D5CB 31B7 D20A 0618
> 
> -- 
> To unsubscribe, send mail to [email protected].



They following code in the "format" function does it for me:

        if type(var) == "string" then
                var = var:gsub("-", "%%-")
        end

        format = format:gsub("$" .. var, val)


If I omit the if-clause, then there are errors like this, but i do not know in 
which
case "var" contains a number.

        vicious/helpers.lua:57: attempt to index local 'var' (a number value)

However i agree to you that this is a messi solution.


regards Sascha




-- 
To unsubscribe, send mail to [email protected].

Reply via email to