From eb2fd618fe863204c83553c5e5c7c2fe972e7328 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Mon, 19 Jan 2015 16:16:06 -0500 Subject: [PATCH] Fix accidental negative bounds See Araq/Nim #1979 for context --- src/nre.nim | 2 +- test/find.nim | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nre.nim b/src/nre.nim index c0c286b0d0..8bec3d9905 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -116,7 +116,7 @@ proc `[]`*(pattern: Captures, i: int): string = # capture count, plus the entire string pattern.matchCache = newSeq[string](pattern.pattern.captureCount + 1) if pattern.matchCache[i + 1] == nil: - pattern.matchCache[i + 1] = pattern.str[bounds.a .. bounds.b-1] + pattern.matchCache[i + 1] = pattern.str.substr(bounds.a, bounds.b-1) return pattern.matchCache[i + 1] else: return nil diff --git a/test/find.nim b/test/find.nim index d8df958f9c..f4f72c778a 100644 --- a/test/find.nim +++ b/test/find.nim @@ -19,3 +19,4 @@ suite "find": test "len 0 find": check("".findAll(re"\ ") == newSeq[string]()) check("".findAll(re"") == @[""]) + check("word word".findAll(nre.re"\b") == @["", "", "", ""])