diff options
author | Carlo Capocasa <carlo@capocasa.net> | 2021-12-13 07:29:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-13 07:29:22 +0100 |
commit | 0ff4b2ba7ee74ed2758b0eb5992e4ccab7433952 (patch) | |
tree | ead0619e45e2af6d33dbfb9b70b20a590b29aba1 /lib | |
parent | 4b5cecd902cc4126ff9d6cda9edb78a13a421239 (diff) | |
download | Nim-0ff4b2ba7ee74ed2758b0eb5992e4ccab7433952.tar.gz |
fix bug #14468 zero-width split (#19248)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/impure/re.nim | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/impure/re.nim b/lib/impure/re.nim index 8e5efbb28..4eacf0091 100644 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -556,19 +556,22 @@ iterator split*(s: string, sep: Regex; maxsplit = -1): string = @["", "this", "is", "an", "example", ""] var last = 0 var splits = maxsplit - var x: int + var x = -1 + if len(s) == 0: + last = 1 + if matchLen(s, sep, 0) == 0: + x = 0 while last <= len(s): var first = last var sepLen = 1 + if x == 0: + inc(last) while last < len(s): x = matchLen(s, sep, last) if x >= 0: sepLen = x break inc(last) - if x == 0: - if last >= len(s): break - inc last if splits == 0: last = len(s) yield substr(s, first, last-1) if splits == 0: break |