aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings/strings.go
diff options
context:
space:
mode:
authorScott Lawrence <bytbox@gmail.com>2010-08-03 13:35:14 +1000
committerRob Pike <r@golang.org>2010-08-03 13:35:14 +1000
commit0cd877725597a9e7c35afdcdb1dbcd1c2c4264b8 (patch)
treea102aeea3ec00f91fd2667f3ba6f9632769a3e5f /src/pkg/strings/strings.go
parentb6c2bf7127fcd65eb3de1a8cae8925ea042ad7e2 (diff)
downloadgo-0cd877725597a9e7c35afdcdb1dbcd1c2c4264b8.tar.xz
strings: fix Split("", "", -1)
Fixes #980. Made it return an empty array, rather than crash. Added relevant test cases to strings. R=golang-dev, r CC=golang-dev https://golang.org/cl/1914041
Diffstat (limited to 'src/pkg/strings/strings.go')
-rw-r--r--src/pkg/strings/strings.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go
index 12be04c239..c332f4567d 100644
--- a/src/pkg/strings/strings.go
+++ b/src/pkg/strings/strings.go
@@ -28,8 +28,10 @@ func explode(s string, n int) []string {
a[i] = string(rune)
cur += size
}
- // add the rest
- a[i] = s[cur:]
+ // add the rest, if there is any
+ if cur < len(s) {
+ a[i] = s[cur:]
+ }
return a
}