Skip to content

Character between U+0001 ~ U+001F in string should be escaped when serialized #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2017

Conversation

ak1t0
Copy link
Contributor

@ak1t0 ak1t0 commented Mar 19, 2017

Fixes servo/servo#15947


This change is Reviewable

@nox
Copy link
Contributor

nox commented Mar 19, 2017

r? @SimonSapin

@SimonSapin
Copy link
Member

Reviewed 1 of 1 files at r1.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


src/serializer.rs, line 260 at r1 (raw file):

                b'\r' => "\\D ",
                b'\0' => "\u{FFFD}",
                x if (x >= b'\x01' && x <= b'\x1F') || x == b'\x7F' => {

A range pattern here would look nicer than a guard:b'\x01'...b'\x1F' | b'\x7F'


src/serializer.rs, line 261 at r1 (raw file):

                b'\0' => "\u{FFFD}",
                x if (x >= b'\x01' && x <= b'\x1F') || x == b'\x7F' => {
                    string = format!("\\{:x} ", x);

format! does memory allocation in order to return a string, which can be costly. To avoid it, change the type of this match expression from &str to Option<&str> (so wrapping str literals in Some( ) in other branches) where None indicates that the byte needs to be hexadecimal-escaped. Below, use try!(write!(self.inner, "\\{:x}", b)); in that case to write directly to the output stream without an intermediate String.


Comments from Reviewable

@ak1t0
Copy link
Contributor Author

ak1t0 commented Mar 21, 2017

I fixed that as it was pointed out to me.

@SimonSapin
Copy link
Member

Thank you! Looks good.

@bors-servo r+


Reviewed 1 of 1 files at r2, 1 of 1 files at r3.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@bors-servo
Copy link
Contributor

📌 Commit 8214af3 has been approved by SimonSapin

@bors-servo
Copy link
Contributor

⌛ Testing commit 8214af3 with merge 20b509a...

bors-servo pushed a commit that referenced this pull request Mar 21, 2017
Character between U+0001 ~ U+001F in string should be escaped when serialized

Fixes [servo/servo#15947](servo/servo#15947)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/129)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: SimonSapin
Pushing 20b509a to master...

@bors-servo bors-servo merged commit 8214af3 into servo:master Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants