unicode/norm: bug fix in Iter

i.p is overwritten by setDone, so must be saved before
calling it.

Fixes golang/go#20710

Change-Id: I5744687c11f0c1101712bb5aa290ebe009ff6d05
Reviewed-on: https://go-review.googlesource.com/c/145559
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ross Light <light@google.com>
diff --git a/unicode/norm/iter.go b/unicode/norm/iter.go
index ce17f96..417c6b2 100644
--- a/unicode/norm/iter.go
+++ b/unicode/norm/iter.go
@@ -128,8 +128,9 @@
 func nextASCIIBytes(i *Iter) []byte {
 	p := i.p + 1
 	if p >= i.rb.nsrc {
+		p0 := i.p
 		i.setDone()
-		return i.rb.src.bytes[i.p:p]
+		return i.rb.src.bytes[p0:p]
 	}
 	if i.rb.src.bytes[p] < utf8.RuneSelf {
 		p0 := i.p
diff --git a/unicode/norm/iter_test.go b/unicode/norm/iter_test.go
index d95aa30..5a8fdab 100644
--- a/unicode/norm/iter_test.go
+++ b/unicode/norm/iter_test.go
@@ -9,7 +9,7 @@
 	"testing"
 )
 
-func doIterNorm(f Form, s string) []byte {
+func doIterNormString(f Form, s string) []byte {
 	acc := []byte{}
 	i := Iter{}
 	i.InitString(f, s)
@@ -19,8 +19,21 @@
 	return acc
 }
 
+func doIterNorm(f Form, s string) []byte {
+	acc := []byte{}
+	i := Iter{}
+	i.Init(f, []byte(s))
+	for !i.Done() {
+		acc = append(acc, i.Next()...)
+	}
+	return acc
+}
+
 func TestIterNext(t *testing.T) {
 	runNormTests(t, "IterNext", func(f Form, out []byte, s string) []byte {
+		return doIterNormString(f, string(append(out, s...)))
+	})
+	runNormTests(t, "IterNext", func(f Form, out []byte, s string) []byte {
 		return doIterNorm(f, string(append(out, s...)))
 	})
 }