mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:32:43 +00:00 
			
		
		
		
	 d85b9fd5a0
			
		
	
	
		d85b9fd5a0
		
	
	
	
	
		
			
			This is a partial revert of commit 60064e2, which removed the validation
of RegExp flags during runtime and expected the parser to do that
exclusively - however this was not taking into account the RegExp()
constructor, which was subsequently crashing on invalid flags.
Also adds test for these constructor error cases, which were obviously
missing before.
Fixes #7042.
		
	
			
		
			
				
	
	
		
			31 lines
		
	
	
	
		
			985 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
	
		
			985 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| describe("errors", () => {
 | |
|     test("invalid pattern", () => {
 | |
|         expect(() => {
 | |
|             RegExp("[");
 | |
|         }).toThrowWithMessage(
 | |
|             SyntaxError,
 | |
|             "RegExp compile error: Error during parsing of regular expression:"
 | |
|         );
 | |
|     });
 | |
| 
 | |
|     test("invalid flag", () => {
 | |
|         expect(() => {
 | |
|             RegExp("", "x");
 | |
|         }).toThrowWithMessage(SyntaxError, "Invalid RegExp flag 'x'");
 | |
|     });
 | |
| 
 | |
|     test("repeated flag", () => {
 | |
|         expect(() => {
 | |
|             RegExp("", "gg");
 | |
|         }).toThrowWithMessage(SyntaxError, "Repeated RegExp flag 'g'");
 | |
|     });
 | |
| });
 | |
| 
 | |
| test("basic functionality", () => {
 | |
|     expect(RegExp().toString()).toBe("/(?:)/");
 | |
|     expect(RegExp(undefined).toString()).toBe("/(?:)/");
 | |
|     expect(RegExp("foo").toString()).toBe("/foo/");
 | |
|     expect(RegExp("foo", undefined).toString()).toBe("/foo/");
 | |
|     expect(RegExp("foo", "g").toString()).toBe("/foo/g");
 | |
|     expect(RegExp(undefined, "g").toString()).toBe("/(?:)/g");
 | |
| });
 |