Skip to content

Commit f243b98

Browse files
authored
Fix crash in parseJsxChild found by fuzzing (#53674)
1 parent bebb6d0 commit f243b98

6 files changed

+48
-1
lines changed

src/compiler/parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6013,7 +6013,7 @@ namespace Parser {
60136013
// We want the error span to cover only 'Foo.Bar' in < Foo.Bar >
60146014
// or to cover only 'Foo' in < Foo >
60156015
const tag = openingTag.tagName;
6016-
const start = skipTrivia(sourceText, tag.pos);
6016+
const start = Math.min(skipTrivia(sourceText, tag.pos), tag.end);
60176017
parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
60186018
}
60196019
return undefined;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests/cases/compiler/a.js(1,3): error TS17008: JSX element '' has no corresponding closing tag.
2+
tests/cases/compiler/a.js(1,4): error TS1003: Identifier expected.
3+
tests/cases/compiler/a.js(1,5): error TS1005: '...' expected.
4+
tests/cases/compiler/a.js(3,1): error TS1005: '</' expected.
5+
6+
7+
==== tests/cases/compiler/a.js (4 errors) ====
8+
!< {:>
9+
10+
!!! error TS17008: JSX element '' has no corresponding closing tag.
11+
~
12+
!!! error TS1003: Identifier expected.
13+
~
14+
!!! error TS1005: '...' expected.
15+
16+
17+
18+
!!! error TS1005: '</' expected.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [a.js]
2+
!< {:>
3+
4+
5+
6+
//// [a.js]
7+
!< {...}>
8+
9+
</>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/a.js ===
2+
3+
!< {:>
4+
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/a.js ===
2+
!< {:>
3+
>!< {:> : boolean
4+
>< {:> : any
5+
> : any
6+
> : any
7+
8+
9+
> : any
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @allowJs: true
2+
// @outDir: ./out
3+
// @filename: a.js
4+
!< {:>
5+

0 commit comments

Comments
 (0)