Skip to content
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

Alternate handling of out of order tag closing #78

Closed
hiconversion opened this issue Mar 1, 2014 · 2 comments
Closed

Alternate handling of out of order tag closing #78

hiconversion opened this issue Mar 1, 2014 · 2 comments

Comments

@hiconversion
Copy link

Ran into a problematic website with mismatched open and close tags.

It appears the following code in Parser.prototype.onclosetag tries to make better sense out of mismatched close tags by popping the open tags off the stack until reaching the tag being closed:

    var pos = this._stack.lastIndexOf(name);
    if(pos !== -1){
        if(this._cbs.onclosetag){
            pos = this._stack.length - pos;
            while(pos--) this._cbs.onclosetag(this._stack.pop());
        }
        else this._stack.length = pos;
    ...

Sending the re-ordered tags to the browser then caused the rendering to look awful.

The question would be, is it reasonable to just attempt to reconstruct the original flawed order this by pulling out the tag?

  var pos = this._stack.lastIndexOf(name);
  if(pos !== -1){
      this._stack.splice(pos,1);
      if (this._cbs.onclosetag) {
          this._cbs.onclosetag(name);
      }

With this modification, ff, chrome, ie all now rendered properly with this "flawed" html. Being unaware of the potential impact to other code and scenarios that might expect the current tag closing behavior, I put this up for discussion.

@fb55
Copy link
Owner

fb55 commented Mar 1, 2014

I know the current solution is flawed, but your change doesn't improve the situation, either, as it breaks existing projects.

@hiconversion
Copy link
Author

Understood. And certainly as I look into the issue further, there are leftover tags, etc. I guess there is a limit to much bad HTML one can "forgive". Thanks for the quick response. I'll close this then.

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

No branches or pull requests

1 participant