summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorChris Heller <chris.heller@greyheller.com>2016-12-16 01:33:44 -0800
committerChris Heller <chris.heller@greyheller.com>2016-12-21 12:06:59 -0800
commit40d034b7e37dd3d19f324ec8bcef5fafc03fed2a (patch)
tree27499ca97467b2d22ab318833e806749de97a0d3 /lib
parent2bb49136de3e3d798c4bf37d23f34ee868e7ebf7 (diff)
downloadNim-40d034b7e37dd3d19f324ec8bcef5fafc03fed2a.tar.gz
Guard against calling split with an empty string as a separator. Fixes #5119
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/strutils.nim5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 14877eb4d..45c2669f9 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -808,6 +808,11 @@ proc split*(s: string, sep: string, maxsplit: int = -1): seq[string] {.noSideEff
   ##
   ## Substrings are separated by the string `sep`. This is a wrapper around the
   ## `split iterator <#split.i,string,string>`_.
+  ##
+  ## If `sep` is an empty string, `ValueError` is raised.
+  if sep.len == 0:
+    raise newException(ValueError, "invalid separator: empty string not allowed")
+  
   accumulateResult(split(s, sep, maxsplit))
 
 proc rsplit*(s: string, seps: set[char] = Whitespace,