Log In  

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 "".

P#101424 2021-12-04 07:51

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()



function _sub(a,b,c)
  if (b==nil) b=1
  if (c==nil) c=-1
  if (#a<b) return ""
  return sub(a,b,c)
P#101518 2021-12-05 05:29 ( Edited 2021-12-05 05:29)

Thanks @thisismypassword -- this is indeed extremely wrong and I'll patch it shortly in 0.2.4b

P#101529 2021-12-05 09:19

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
P#102168 2021-12-09 07:38 ( Edited 2021-12-09 07:39)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2022-12-03 15:56:01 | 0.015s | Q:14