diff --git a/src/parse.rs b/src/parse.rs index 307e0650..2a87948a 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -472,6 +472,10 @@ fn raw_string(input: Cursor) -> Result { _ => return Err(Reject), } } + if n > 255 { + // https://github.com/rust-lang/rust/pull/95251 + return Err(Reject); + } while let Some((i, ch)) = chars.next() { match ch { '"' if input.rest[i + 1..].starts_with(&input.rest[..n]) => { diff --git a/tests/test.rs b/tests/test.rs index 5a8e93fe..e0af1512 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -5,6 +5,7 @@ )] use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::iter; use std::panic; use std::str::{self, FromStr}; @@ -118,6 +119,25 @@ fn literal_string() { #[test] fn literal_raw_string() { "r\"\r\n\"".parse::().unwrap(); + + fn raw_string_literal_with_hashes(n: usize) -> String { + let mut literal = String::new(); + literal.push('r'); + literal.extend(iter::repeat('#').take(n)); + literal.push('"'); + literal.push('"'); + literal.extend(iter::repeat('#').take(n)); + literal + } + + raw_string_literal_with_hashes(255) + .parse::() + .unwrap(); + + // https://github.com/rust-lang/rust/pull/95251 + raw_string_literal_with_hashes(256) + .parse::() + .unwrap_err(); } #[test]