Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap the regress error for now #1027

Merged
merged 1 commit into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions boa/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl RegExp {
pub(crate) const LENGTH: usize = 2;

/// Create a new `RegExp`
pub(crate) fn constructor(this: &Value, args: &[Value], _: &mut Context) -> Result<Value> {
pub(crate) fn constructor(this: &Value, args: &[Value], ctx: &mut Context) -> Result<Value> {
let arg = args.get(0).ok_or_else(Value::undefined)?;

let (regex_body, mut regex_flags) = match arg {
Expand Down Expand Up @@ -161,8 +161,15 @@ impl RegExp {
sorted_flags.push('y');
}

let matcher = Regex::with_flags(&regex_body, sorted_flags.as_str())
.expect("failed to create matcher");
let matcher = match Regex::with_flags(&regex_body, sorted_flags.as_str()) {
Err(error) => {
return Err(
ctx.construct_syntax_error(format!("failed to create matcher: {}", error.text))
);
}
Ok(val) => val,
};

let regexp = RegExp {
matcher,
use_last_index: global || sticky,
Expand Down
9 changes: 9 additions & 0 deletions boa/src/builtins/regexp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,12 @@ fn to_string() {
);
assert_eq!(forward(&mut context, "/\\n/g.toString()"), "\"/\\n/g\"");
}

#[test]
fn no_panic_on_invalid_character_escape() {
let mut context = Context::new();

// This used to panic, we now return an error
// The line below should not cause Boa to panic
forward(&mut context, r"const a = /,\;/");
}