Skip to content

Feature request: Ability to serialize malformed token stream #292

Closed

Description

@jrobsonchase

We have a use case that requires the ability to re-serialize malformed html input without needing to insert extra open tags to appease the Serializer, which panics when it tries to serialize a close tag when the stack is empty.

The obvious (naive perhaps?) solution is to provide a mechanism to manipulate the stack in order to fake the presence of an open tag. Alternatively, the behavior could be changed in the parent and end_elem methods to not panic in the absence of an ElemInfo on the stack, and to instead either create or return a sane default. I'll start working on it from that angle, but I'm open to alternative approaches.

Activity

  1. jrobsonchase commented on Aug 1, 2017

    @jrobsonchase
    ContributorAuthor

    On further inspection, the stack that's causing me so much headache is only in the html5ever implementation of the Serializer trait, which doesn't have any notion of a stack. So now I'm thinking it's likely a mistake to expose it through that interface since there may not even be a stack behind the scenes.

  2. Ygg01 commented on Aug 2, 2017

    @Ygg01
    Contributor

    @jechas01 Could you elaborate a bit more? What do you mean by re-serialize? You serialize, parse and then serialize again? Do you do modifications during tokenization/treebuilding that aren't in HTML5 spec?

  3. jrobsonchase commented on Aug 2, 2017

    @jrobsonchase
    ContributorAuthor

    We tokenize input which may or may not be valid/complete, do some modifications such as removing tags or attributes, and then re-serialize whatever is left. None of our processing will make the html invalid per the HTML5 spec, but it may come to us that way.

    Sorry, should have linked back to the PR that spawned this issue, #277

  4. changed the title [-]Feature request: API to manipulate the Serializer stack[/-] [+]Feature request: Ability to serialize malformed token stream[/+] on Aug 2, 2017
  5. added a commit that references this issue on Aug 14, 2017
    84a8ea8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions