String literal matching throws an exception for length < 2
Closed this issue · 1 comments
bluelhf commented
Describe the bug
When StringLiteral matches some input, it does not do bounds checks prior to calling String#substring(int, int) to get the potential content of the string literal. For obvious reasons, this fails for inputs of length 1 — the result is an attempted substring from index 1 inclusive to index 0 exclusive.
To Reproduce
Steps to reproduce the behavior:
- Load this script:
on script load:
trigger:
// This is initially parsed as a less-than comparison,
// causing the parser to attempt to match ", which breaks
// string literal's content matching
set {foo} to "Hello " + "<there!"
- Notice the ScriptCompileError: An unknown error occurred while compiling, caused by a SIOOBE when matching " in StringLiteral.
- Realise that you cannot set {foo} to "Hello <there!", and become overwhelmed with panic.
Expected behavior
The input should compile as the addition of the string literals "test" and "<hello".
Additional context
I'm running ByteSkript version 1.0.21.
Suggested changes
Add a guard condition to the matcher, which returns null if the length of the string is less than 2.
Moderocky commented
Fixed in .22