Skip to content

Commit

Permalink
Fix panic during malformed empty interpolated string (#333)
Browse files Browse the repository at this point in the history
Fixes #332
  • Loading branch information
JohnnyMorganz authored Dec 30, 2024
1 parent 671a289 commit cdf5614
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Luau: added support for user defined type functions (rfc: https://github.com/luau-lang/rfcs/blob/master/docs/user-defined-type-functions.md)

### Fixed
- Fixed a panic when parsing a malformed empty interpolated string, e.g. ``print(`{}`)``

## [1.1.2] - 2024-11-17

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion full-moon/src/ast/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ fn parse_primary_expression(state: &mut ParserState) -> ParserResult<Expression>
))
}

other => unreachable!("unexpected interpolated string kind: {other:?}"),
_ => ParserResult::NotFound,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
source: full-moon/tests/fail_cases.rs
expression: result.ast()
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
nodes:
stmts:
- - FunctionCall:
prefix:
Name:
leading_trivia: []
token:
start_position:
bytes: 0
line: 1
character: 1
end_position:
bytes: 5
line: 1
character: 6
token_type:
type: Identifier
identifier: print
trailing_trivia: []
suffixes:
- Call:
AnonymousCall:
Parentheses:
parentheses:
tokens:
- leading_trivia: []
token:
start_position:
bytes: 5
line: 1
character: 6
end_position:
bytes: 6
line: 1
character: 7
token_type:
type: Symbol
symbol: (
trailing_trivia: []
- leading_trivia: []
token:
start_position:
bytes: 10
line: 1
character: 11
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Symbol
symbol: )
trailing_trivia: []
arguments:
pairs:
- End:
InterpolatedString:
segments: []
last_string:
leading_trivia: []
token:
start_position:
bytes: 6
line: 1
character: 7
end_position:
bytes: 8
line: 1
character: 9
token_type:
type: InterpolatedString
literal: ""
kind: Begin
trailing_trivia: []
- ~
eof:
leading_trivia: []
token:
start_position:
bytes: 11
line: 1
character: 12
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Eof
trailing_trivia: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: full-moon/tests/fail_cases.rs
expression: ast.to_string()
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
"print(`{)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: full-moon/tests/fail_cases.rs
expression: "String::from_utf8(output.into_inner()).unwrap()"
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
error[ast]: expected expression after `{`
┌─ source.lua:1:7
1 │ print(`{}`)
│ ^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: full-moon/tests/fail_cases.rs
expression: result.errors()
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
- AstError:
token:
start_position:
bytes: 6
line: 1
character: 7
end_position:
bytes: 8
line: 1
character: 9
token_type:
type: InterpolatedString
literal: ""
kind: Begin
additional: "expected expression after `{`"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print(`{}`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
source: full-moon/tests/fail_cases.rs
expression: tokens
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
- start_position:
bytes: 0
line: 1
character: 1
end_position:
bytes: 5
line: 1
character: 6
token_type:
type: Identifier
identifier: print
- start_position:
bytes: 5
line: 1
character: 6
end_position:
bytes: 6
line: 1
character: 7
token_type:
type: Symbol
symbol: (
- start_position:
bytes: 6
line: 1
character: 7
end_position:
bytes: 8
line: 1
character: 9
token_type:
type: InterpolatedString
literal: ""
kind: Begin
- start_position:
bytes: 8
line: 1
character: 9
end_position:
bytes: 10
line: 1
character: 11
token_type:
type: InterpolatedString
literal: ""
kind: End
- start_position:
bytes: 10
line: 1
character: 11
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Symbol
symbol: )
- start_position:
bytes: 11
line: 1
character: 12
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Eof

0 comments on commit cdf5614

Please sign in to comment.