Skip to content

Commit cc7a160

Browse files
committed
Touch up PR 1175
1 parent 0f942e5 commit cc7a160

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/read.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -877,15 +877,13 @@ fn parse_escape<'de, R: Read<'de>>(
877877
b'r' => scratch.push(b'\r'),
878878
b't' => scratch.push(b'\t'),
879879
b'u' => return parse_unicode_escape(read, validate, scratch),
880-
_ => {
881-
return error(read, ErrorCode::InvalidEscape);
882-
}
880+
_ => return error(read, ErrorCode::InvalidEscape),
883881
}
884882

885883
Ok(())
886884
}
887885

888-
/// Parses a JSON \u escape and appends it into the scratch space. Assumes \u
886+
/// Parses a JSON \u escape and appends it into the scratch space. Assumes `\u`
889887
/// has just been read.
890888
#[cold]
891889
fn parse_unicode_escape<'de, R: Read<'de>>(
@@ -895,10 +893,10 @@ fn parse_unicode_escape<'de, R: Read<'de>>(
895893
) -> Result<()> {
896894
let mut n = tri!(read.decode_hex_escape());
897895

898-
// Non-BMP characters are encoded as a sequence of two hex
899-
// escapes, representing UTF-16 surrogates. If deserializing a
900-
// utf-8 string the surrogates are required to be paired,
901-
// whereas deserializing a byte string accepts lone surrogates.
896+
// Non-BMP characters are encoded as a sequence of two hex escapes,
897+
// representing UTF-16 surrogates. If deserializing a utf-8 string the
898+
// surrogates are required to be paired, whereas deserializing a byte string
899+
// accepts lone surrogates.
902900
if validate && n >= 0xDC00 && n <= 0xDFFF {
903901
// XXX: This is actually a trailing surrogate.
904902
return error(read, ErrorCode::LoneLeadingSurrogateInHexEscape);
@@ -935,11 +933,10 @@ fn parse_unicode_escape<'de, R: Read<'de>>(
935933
error(read, ErrorCode::UnexpectedEndOfHexEscape)
936934
} else {
937935
push_wtf8_codepoint(n1 as u32, scratch);
938-
// The \ prior to this byte started an escape sequence,
939-
// so we need to parse that now. This recursive call
940-
// does not blow the stack on malicious input because
941-
// the escape is not \u, so it will be handled by one
942-
// of the easy nonrecursive cases.
936+
// The \ prior to this byte started an escape sequence, so we
937+
// need to parse that now. This recursive call does not blow the
938+
// stack on malicious input because the escape is not \u, so it
939+
// will be handled by one of the easy nonrecursive cases.
943940
parse_escape(read, validate, scratch)
944941
};
945942
}
@@ -956,8 +953,8 @@ fn parse_unicode_escape<'de, R: Read<'de>>(
956953
continue;
957954
}
958955

959-
// This value is in range U+10000..=U+10FFFF, which is always a
960-
// valid codepoint.
956+
// This value is in range U+10000..=U+10FFFF, which is always a valid
957+
// codepoint.
961958
let n = (((n1 - 0xD800) as u32) << 10 | (n2 - 0xDC00) as u32) + 0x1_0000;
962959
push_wtf8_codepoint(n, scratch);
963960
return Ok(());

0 commit comments

Comments
 (0)