It seems when the index parameters are out of bounds, sub now returns the last character in the string, instead of "", which breaks string parsing code.
As an example of incorrect result, sub("a",2,2)
returns "a", whereas it's supposed to (and used to) return "".
You are CORRECT, @thisismypassword ! Wow, that is a very serious error. I use strings all the time and that will definitely break some of the stuff I've done.
A temporary fix I guess is:
-- fix error in sub function _init() cls() a="apple" ?"1:"..sub(a) ?"2:".._sub(a) ?"1:"..sub(a,2) ?"2:".._sub(a,2) ?"1:"..sub(a,3,4) ?"2:".._sub(a,3,4) ?"1:"..sub(a,6,6) ?"2:".._sub(a,6,6) end function _sub(a,b,c) if (b==nil) b=1 if (c==nil) c=-1 if (#a<b) return "" return sub(a,b,c) end |
4
Thanks @thisismypassword -- this is indeed extremely wrong and I'll patch it shortly in 0.2.4b
It only seems to fail if the first index is too high, so here's a quick workaround for anyone waiting for @zep to fix it:
_sub,sub=sub,function(s,a,b) return a and a>#s and "" or _sub(s,a,b) end |
[Please log in to post a comment]