Ensure JS RegExp does not contain line terminators
This commit is contained in:
parent
da830939d7
commit
a9eab38d88
|
@ -3,6 +3,7 @@ pub enum ErrorType {
|
|||
NoSpaceBeforeAttr,
|
||||
UnterminatedCssString,
|
||||
UnterminatedJsString,
|
||||
UnterminatedJsRegExp,
|
||||
CharNotFound { need: u8, got: u8 },
|
||||
MatchNotFound(&'static [u8]),
|
||||
NotFound(&'static str),
|
||||
|
@ -25,6 +26,9 @@ impl ErrorType {
|
|||
ErrorType::UnterminatedJsString => {
|
||||
format!("Unterminated JavaScript string.")
|
||||
}
|
||||
ErrorType::UnterminatedJsRegExp => {
|
||||
format!("Unterminated JavaScript regular expression.")
|
||||
}
|
||||
ErrorType::CharNotFound { need, got } => {
|
||||
format!("Expected {} (U+{:X}), got {} (U+{:X}).", need as char, need, got as char, got)
|
||||
}
|
||||
|
|
|
@ -126,6 +126,11 @@ fn parse_literal_regex(proc: &mut Processor) -> ProcessingResult<()> {
|
|||
|
||||
loop {
|
||||
let c = proc.accept()?;
|
||||
// We've already accepted char, so we can't use proc.match_line_terminator.
|
||||
// Line terminator cannot be escaped and is always invalid in a RegExp literal.
|
||||
if c == b'\r' || c == b'\n' {
|
||||
return Err(ErrorType::UnterminatedJsRegExp);
|
||||
};
|
||||
|
||||
if c == b'\\' {
|
||||
// If already escaping, then ignore backslash (interpret literally) and continue.
|
||||
|
|
Loading…
Reference in New Issue