Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Make escape_char safe #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,8 @@ fn escape_str(wr: &mut fmt::Write, v: &str) -> EncodeResult<()> {

fn escape_char(writer: &mut fmt::Write, v: char) -> EncodeResult<()> {
let mut buf = [0; 4];
let _ = write!(&mut &mut buf[..], "{}", v);
let buf = unsafe { str::from_utf8_unchecked(&buf[..v.len_utf8()]) };
escape_str(writer, buf)
let s = v.encode_utf8(&mut buf);
escape_str(writer, s)
}

fn spaces(wr: &mut fmt::Write, n: u32) -> EncodeResult<()> {
Expand Down