diff --git a/src/parse.rs b/src/parse.rs index e389be74..6ef6cc23 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -644,7 +644,7 @@ impl<'a> Bytes<'a> { match self.bytes.get(1) { Some(b'"') => return Err(Error::ExpectedIdentifier), Some(b'r') => match self.bytes.get(2) { - Some(b'"') => return Err(Error::ExpectedIdentifier), + Some(b'#' | b'"') => return Err(Error::ExpectedIdentifier), Some(_) | None => (), }, Some(_) | None => (), diff --git a/tests/438_rusty_byte_strings.rs b/tests/438_rusty_byte_strings.rs index d8f4f639..58a273ff 100644 --- a/tests/438_rusty_byte_strings.rs +++ b/tests/438_rusty_byte_strings.rs @@ -155,6 +155,69 @@ fn fuzzer_failures() { .unwrap(), "b\"{\x00\x00\x00\x00\"" ); + + // `br#` should be parsed as the start of a byte string, not the identifier `br` and a `#` + assert_eq!( + ron::from_str(r##"br#"""#"##), + Ok(ron::Value::Bytes(vec![34])) + ); + assert_eq!( + ron::from_str(r##"{"error": br#"""#}"##), + Ok(ron::Value::Map( + [( + ron::Value::String(String::from("error")), + ron::Value::Bytes(vec![34]) + )] + .into_iter() + .collect() + )) + ); + assert_eq!( + ron::from_str( + r##"#![enable(unwrap_newtypes)] + #![enable(unwrap_variant_newtypes)] + Some({"error": br#"""#}) + "## + ), + Ok(ron::Value::Option(Some(Box::new(ron::Value::Map( + [( + ron::Value::String(String::from("error")), + ron::Value::Bytes(vec![34]) + )] + .into_iter() + .collect() + ))))) + ); + + // `br"` should be parsed as the start of a byte string, not the identifier `br` and a `"` + assert_eq!(ron::from_str(r#"br"""#), Ok(ron::Value::Bytes(vec![]))); + assert_eq!( + ron::from_str(r#"{"error": br""}"#), + Ok(ron::Value::Map( + [( + ron::Value::String(String::from("error")), + ron::Value::Bytes(vec![]) + )] + .into_iter() + .collect() + )) + ); + assert_eq!( + ron::from_str( + r#"#![enable(unwrap_newtypes)] + #![enable(unwrap_variant_newtypes)] + Some({"error": br""}) + "# + ), + Ok(ron::Value::Option(Some(Box::new(ron::Value::Map( + [( + ron::Value::String(String::from("error")), + ron::Value::Bytes(vec![]) + )] + .into_iter() + .collect() + ))))) + ); } #[test]