Skip to content

Don't bail on empty Serializer stack - #293

Merged
bors-servo merged 3 commits into
servo:masterfrom
jrobsonchase:no_stack_panics
Aug 14, 2017
Merged

bors-servo merged 3 commits into
servo:masterfrom
jrobsonchase:no_stack_panics

Conversation

@jrobsonchase

Copy link
Copy Markdown
Contributor

This prevents panics if end_elem or parent is called with an empty stack by fabricating a new default ElemInfo.

Normally, this will never happen with valid html, but in the event that someone needs to serialize a token stream representing a malformed tree, they can now do so.

Fixes #292

@Ygg01 Ygg01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. Hopefully, others will comment and close this PR.

@jdm

jdm commented Aug 2, 2017

Copy link
Copy Markdown
Member

One thing that would help me understand is a unit test that fails before these changes and passes afterwards.

@Ygg01 Ygg01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these changes? I don't remember them being originally here yesterday?

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #295) made this pull request unmergeable. Please resolve the merge conflicts.

@jrobsonchase

Copy link
Copy Markdown
Contributor Author

Whoops, must have messed something up when I reverted an accidental push. Still working on a test case.

@jrobsonchase
jrobsonchase force-pushed the no_stack_panics branch 3 times, most recently from b0087da to 0978968 Compare August 3, 2017 15:36
@jrobsonchase

Copy link
Copy Markdown
Contributor Author

OK, now the malformed_tokens test added in 20b04ab will fail with thread 'malformed_tokens' panicked at 'no parent ElemInfo', /checkout/src/libcore/option.rs:819:4
without 0978968.

@Ygg01

Ygg01 commented Aug 14, 2017

Copy link
Copy Markdown
Contributor

@bors-servo: r+

@bors-servo

Copy link
Copy Markdown
Contributor

@Ygg01: 🔑 Insufficient privileges: Not in reviewers

Comment thread html5ever/src/serialize/mod.rs Outdated

fn end_elem(&mut self, name: QualName) -> io::Result<()> {
let info = self.stack.pop().expect("no ElemInfo");
let info = self.stack.pop().unwrap_or_else(|| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than unconditionally creating a missing element, I would prefer to add an option to SerializeOpts and only create the parent if this behaviour is specifically requested.

Comment thread html5ever/tests/serializer.rs Outdated

test!(misnest, r#"<p><i>Hello!</p>, World!</i>"#,
r#"<p><i>Hello!</i></p><i>, World!</i>"#);
test!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes caused by running rustfmt? I would prefer to split them into a separate commit or revert them entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah. Thought I git add -p'd around them, but I guess not. Should be an easy change.

@jdm

jdm commented Aug 14, 2017

Copy link
Copy Markdown
Member

@bors-servo: r+
Thanks!

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 703d141 has been approved by jdm

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 703d141 with merge 84a8ea8...

bors-servo pushed a commit that referenced this pull request Aug 14, 2017
Don't bail on empty Serializer stack

This prevents panics if `end_elem` or `parent` is called with an empty stack by fabricating a new default ElemInfo.

Normally, this will never happen with valid html, but in the event that someone needs to serialize a token stream representing a malformed tree, they can now do so.

Fixes #292
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - status-travis
Approved by: jdm
Pushing 84a8ea8 to master...

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