From 279e4b045133bad59e349520547e5220408b232e Mon Sep 17 00:00:00 2001 From: Anatoly Galiulin Date: Mon, 13 Feb 2017 19:35:40 +0700 Subject: [PATCH] Fixes #5382 --- lib/impure/re.nim | 2 +- tests/stdlib/tbug5382.nim | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/stdlib/tbug5382.nim diff --git a/lib/impure/re.nim b/lib/impure/re.nim index 9d5d2bdd07..e00f91de17 100644 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -290,7 +290,7 @@ proc find*(buf: cstring, pattern: Regex, matches: var openArray[string], for i in 1..int(res)-1: var a = rawMatches[i * 2] var b = rawMatches[i * 2 + 1] - if a >= 0'i32: matches[i-1] = bufSubstr(buf, int(a), int(b)-1) + if a >= 0'i32: matches[i-1] = bufSubstr(buf, int(a), int(b)) else: matches[i-1] = nil return rawMatches[0] diff --git a/tests/stdlib/tbug5382.nim b/tests/stdlib/tbug5382.nim new file mode 100644 index 0000000000..c86656d32b --- /dev/null +++ b/tests/stdlib/tbug5382.nim @@ -0,0 +1,11 @@ +discard """ + output: ''' +02 +''' +""" +import re + +let regexp = re"^\/([0-9]{2})\.html$" +var matches: array[1, string] +discard "/02.html".find(regexp, matches) +echo matches[0]