html: fix tokenizer error

Trailing '<' entities in the text token make the tokenizer fail
for escapable raw text elements like title and textarea

Fixes golang/go#34281

Change-Id: I6fe8f2229b5fd639cf5a02ab1db31f18ea034c8b
GitHub-Last-Rev: 4a9da031771882a2798ceae57d4f8a983d4dcbf9
GitHub-Pull-Request: golang/net#53
Reviewed-on: https://go-review.googlesource.com/c/net/+/196620
Run-TryBot: Kunpei Sakai <kunpei@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
diff --git a/html/token.go b/html/token.go
index b426ae0..ae0d1b0 100644
--- a/html/token.go
+++ b/html/token.go
@@ -347,6 +347,7 @@
 			break loop
 		}
 		if c != '/' {
+			z.raw.end--
 			continue loop
 		}
 		if z.readRawEndTag() || z.err != nil {
diff --git a/html/token_test.go b/html/token_test.go
index f2473ba..d59c3c6 100644
--- a/html/token_test.go
+++ b/html/token_test.go
@@ -258,6 +258,11 @@
 		"<title><b>K&amp;R C</b></title>",
 		"<title>$&lt;b&gt;K&amp;R C&lt;/b&gt;$</title>",
 	},
+	{
+		"title with trailing '&lt;' entity",
+		"<title>foobar<</title>",
+		"<title>$foobar&lt;$</title>",
+	},
 	// DOCTYPE tests.
 	{
 		"Proper DOCTYPE",