libsyntax: Forbid escapes in the inclusive range \x80
-\xff
in
Unicode characters and strings. Use `\u0080`-`\u00ff` instead. ASCII/byte literals are unaffected. This PR introduces a new function, `escape_default`, into the ASCII module. This was necessary for the pretty printer to continue to function. RFC #326. Closes #18062. [breaking-change]
This commit is contained in:
parent
bb70ee56db
commit
e8d6031c71
12 changed files with 4276 additions and 4191 deletions
|
@ -720,7 +720,11 @@ impl<'a> StringReader<'a> {
|
|||
|
||||
/// Scan over `n_digits` hex digits, stopping at `delim`, reporting an
|
||||
/// error if too many or too few digits are encountered.
|
||||
fn scan_hex_digits(&mut self, n_digits: uint, delim: char) -> bool {
|
||||
fn scan_hex_digits(&mut self,
|
||||
n_digits: uint,
|
||||
delim: char,
|
||||
below_0x7f_only: bool)
|
||||
-> bool {
|
||||
debug!("scanning {} digits until {}", n_digits, delim);
|
||||
let start_bpos = self.last_pos;
|
||||
let mut accum_int = 0;
|
||||
|
@ -745,6 +749,13 @@ impl<'a> StringReader<'a> {
|
|||
self.bump();
|
||||
}
|
||||
|
||||
if below_0x7f_only && accum_int >= 0x80 {
|
||||
self.err_span_(start_bpos,
|
||||
self.last_pos,
|
||||
"this form of character escape may only be used \
|
||||
with characters in the range [\\x00-\\x7f]");
|
||||
}
|
||||
|
||||
match char::from_u32(accum_int) {
|
||||
Some(_) => true,
|
||||
None => {
|
||||
|
@ -773,9 +784,13 @@ impl<'a> StringReader<'a> {
|
|||
Some(e) => {
|
||||
return match e {
|
||||
'n' | 'r' | 't' | '\\' | '\'' | '"' | '0' => true,
|
||||
'x' => self.scan_hex_digits(2u, delim),
|
||||
'u' if !ascii_only => self.scan_hex_digits(4u, delim),
|
||||
'U' if !ascii_only => self.scan_hex_digits(8u, delim),
|
||||
'x' => self.scan_hex_digits(2u, delim, !ascii_only),
|
||||
'u' if !ascii_only => {
|
||||
self.scan_hex_digits(4u, delim, false)
|
||||
}
|
||||
'U' if !ascii_only => {
|
||||
self.scan_hex_digits(8u, delim, false)
|
||||
}
|
||||
'\n' if delim == '"' => {
|
||||
self.consume_whitespace();
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue