[vm/runtime] - Fix RegExp exception messages (issue 52691)

TEST=new test added

Fixed: 52691
Change-Id: Ibc8865f8e9b1e908be80d4fbe8b8931eda448df8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312348
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
asiva 2023-07-06 21:10:28 +00:00 committed by Commit Queue
parent a510e60dbf
commit f84cf9413f
2 changed files with 21 additions and 4 deletions

View file

@ -11,6 +11,7 @@
#include "vm/longjump.h"
#include "vm/object_store.h"
#include "vm/symbols.h"
namespace dart {
@ -432,10 +433,16 @@ void RegExpParser::ReportError(const char* message) {
next_pos_ = in().Length();
// Throw a FormatException on parsing failures.
const String& msg = String::Handle(
String::Concat(String::Handle(String::New(message)), in()));
const Array& args = Array::Handle(Array::New(1));
args.SetAt(0, msg);
Array& args = Array::Handle();
String& str = String::Handle();
args ^= Array::New(3);
str ^= String::New(message);
args.SetAt(0, str);
args.SetAt(1, Symbols::Blank());
args.SetAt(2, in());
str ^= String::ConcatAll(args);
args ^= Array::New(1);
args.SetAt(0, str);
Exceptions::ThrowByType(Exceptions::kFormat, args);
UNREACHABLE();
}

View file

@ -0,0 +1,10 @@
import 'package:expect/expect.dart';
void main() {
try {
var re = RegExp(r'[c-');
} on FormatException catch (e, s) {
Expect.equals(
"FormatException: Unterminated character class [c-", e.toString());
}
}