mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Use template text to improve reparse fuzzing
This commit is contained in:
parent
ec59d9bda5
commit
c60ec02d75
1 changed files with 5 additions and 1 deletions
|
@ -22,12 +22,16 @@ pub struct CheckReparse {
|
|||
|
||||
impl CheckReparse {
|
||||
pub fn from_data(data: &[u8]) -> Option<Self> {
|
||||
const PREFIX: &'static str = "fn main(){\n\t";
|
||||
const SUFFIX: &'static str = "\n}";
|
||||
|
||||
let data = str::from_utf8(data).ok()?;
|
||||
let mut lines = data.lines();
|
||||
let delete_start = usize::from_str(lines.next()?).ok()?;
|
||||
let delete_start = usize::from_str(lines.next()?).ok()? + PREFIX.len();
|
||||
let delete_len = usize::from_str(lines.next()?).ok()?;
|
||||
let insert = lines.next()?.to_string();
|
||||
let text = lines.collect::<Vec<_>>().join("\n");
|
||||
let text = format!("{}{}{}", PREFIX, text, SUFFIX);
|
||||
text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range
|
||||
let delete = TextRange::offset_len(
|
||||
TextUnit::from_usize(delete_start),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue