Repository: sveltejs/svelte (JavaScript)
Date: 2021-06-21 15:43:08+00:00
Task type: Bug Fix

Issue:
</textarea> with the closing angle bracket at a new line gives error
**Describe the bug**
`</textarea>` with the closing angle bracket at a new line gives error.

**Logs**
```
Unexpected end of input (2:1)
```

**To Reproduce**

``` html
<textarea>test</textarea
>
```

**Expected behavior**
Does not give error.

**Stacktraces**
(None)

**Information about your Svelte project:**
- Your browser and the version: Firefox Nightly 2021-05-01
- Your operating system: Arch Linux
- Svelte version: 3.38.1
- Whether your project uses Webpack or Rollup: Maybe unrelated, since it reproduces on REPL.

**Severity**
Not much, but it conflicts with my `prettier` configurations sometimes.

**Additional context**

The case with `<textarea>` gives error, but interestingly the case with `<div>` does not.

----

EDIT: [Got it saved in REPL here](https://svelte.dev/repl/027e752c415f4f12895f714232c5a186?version=3.38.1).


Issue discussion:
Yeah it would be nice to match browsers' behavior for parsing the end of textareas. I'm not sure what that is exactly though.
I always thought that for all browsers it does not matter where the `>` is at, and that is doesn't need to be right after the tag name. Since Prettier does this for all tags I'd be surprised if it doesn't work for `textarea`
@dummdidumm : i confirm that browsers (chrome, safari, Firefox) are handling correctly even if the closing sign `>` is not right after the tag name `</textarea`

After having a closer look it seems that the parser is checking for the exact string `'</textarea>'` without space or breaking line after the tag name 
https://github.com/sveltejs/svelte/blob/a1600ff68e421f952235f09538a2c0a9c6e24b43/src/compiler/parse/state/tag.ts#L224

I did a try using regex test `/\/textarea\s*>/mi` and it seems returning true value when there is spaces/lines-break, but it also generates another error `</textarea> attempted to close an element that was not open (svelte)` after line 224 so it will need more time to implement correctly the logic and relative tests.

Is it ok to continue with this regex approach or do you suggest something else ? @dummdidumm @Conduitry 
yup i checked on https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody, the [end tag allows space, tab, linefeed, formfeed](https://html.spec.whatwg.org/multipage/parsing.html#rcdata-end-tag-name-state) before the `>` character

Solution patch:
diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts
--- a/src/compiler/parse/state/tag.ts
+++ b/src/compiler/parse/state/tag.ts
@@ -221,9 +221,9 @@ export default function tag(parser: Parser) {
 		element.children = read_sequence(
 			parser,
 			() =>
-				parser.template.slice(parser.index, parser.index + 11) === '</textarea>'
+				/^<\/textarea(\s[^>]*)?>/i.test(parser.template.slice(parser.index))
 		);
-		parser.read(/<\/textarea>/);
+		parser.read(/^<\/textarea(\s[^>]*)?>/i);
 		element.end = parser.index;
 	} else if (name === 'script' || name === 'style') {
 		// special case


Test patch:
diff --git a/test/parser/samples/textarea-end-tag/input.svelte b/test/parser/samples/textarea-end-tag/input.svelte
new file mode 100644
--- /dev/null
+++ b/test/parser/samples/textarea-end-tag/input.svelte
@@ -0,0 +1,12 @@
+<textarea>
+	<p>not actu </textar ally an element. {foo}</p>
+</textare
+
+
+> </textaread >asdf</textarea
+
+
+</textarea
+
+>
+
diff --git a/test/parser/samples/textarea-end-tag/output.json b/test/parser/samples/textarea-end-tag/output.json
new file mode 100644
--- /dev/null
+++ b/test/parser/samples/textarea-end-tag/output.json
@@ -0,0 +1,53 @@
+{
+	"html": {
+		"start": 0,
+		"end": 117,
+		"type": "Fragment",
+		"children": [
+			{
+				"start": 0,
+				"end": 117,
+				"type": "Element",
+				"name": "textarea",
+				"attributes": [],
+				"children": [
+					{
+						"start": 10,
+						"end": 51,
+						"type": "Text",
+						"raw": "\n\t<p>not actu </textar ally an element. ",
+						"data": "\n\t<p>not actu </textar ally an element. "
+					},
+					{
+						"start": 50,
+						"end": 55,
+						"type": "MustacheTag",
+						"expression": {
+							"type": "Identifier",
+							"start": 51,
+							"end": 54,
+							"loc": {
+								"start": {
+									"line": 2,
+									"column": 40
+								},
+								"end": {
+									"line": 2,
+									"column": 43
+								}
+							},
+							"name": "foo"
+						}
+					},
+					{
+						"start": 55,
+						"end": 91,
+						"type": "Text",
+						"raw": "</p>\n</textare\n\n\n> </textaread >asdf",
+						"data": "</p>\n</textare\n\n\n> </textaread >asdf"
+					}
+				]
+			}
+		]
+	}
+}
\ No newline at end of file