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

[beta.13] Incorrectly closed tag throws Cannot set property endSourceSpan of null #7849

Closed
ericmartinezr opened this issue Mar 31, 2016 · 6 comments

Comments

@ericmartinezr
Copy link
Contributor

@ericmartinezr ericmartinezr commented Mar 31, 2016

What steps should we try in your demo to see the problem?

Take a look at this plnkr http://plnkr.co/edit/GMMWZ3xVkcGsqlg9m11a?p=preview

The plnkr is using beta 13, to see the correct error message change the version to beta 12 in index.html

Consider this template

template : '<div</div>'

Note that I missed a closing tag for div

Current behavior

Beta 13 throws the following error

EXCEPTION: TypeError: Cannot set property 'endSourceSpan' of null

Expected/desired behavior

Works like beta 12 did throwing this error

Unexpected closing tag "div" ("<div[ERROR ->]</div>"): App@0:4

Other information

@ericmartinezr ericmartinezr changed the title Regression on error message when a tag is not correctly closed [beta.13] Regression on error message when a tag is not correctly closed Mar 31, 2016
@ericmartinezr
Copy link
Contributor Author

@ericmartinezr ericmartinezr commented Apr 1, 2016

Havin this template, with a child node the message is a little bit more clear but unacurrate

template: <div<li></li></div> // I missed closing the starting div tag

Throws

// Makes no sense, <li> is correctly closed
Unexpected closing tag "li" ("<div<li>[ERROR ->]</li></div>"): App@0:8

// Makes sense! But the error message is not where it should be
Unexpected closing tag "div" ("<div<li></li>[ERROR ->]</div>"): App@0:13  
@b-m-f
Copy link

@b-m-f b-m-f commented Apr 14, 2016

The uncaught error happens in angular2/src/compiler/html_parser.ts

where this._getParentElement() is undefined in the function _consumeEndTag

Replacing
this._getParentElement().endSourceSpan = endTagToken.sourceSpan;
with

if(!this._getParentElement() ){
  this.errors.push(HtmlTreeError.create(fullName, endTagToken.sourceSpan, "Unexpected closing tag \"" + endTagToken.parts[1] + "\""));
}
else{
  this._getParentElement().endSourceSpan = endTagToken.sourceSpan;
}

created a better and clearer error message like mentioned from beta 12.

@ericmartinezr ericmartinezr changed the title [beta.13] Regression on error message when a tag is not correctly closed [beta.13] Incorrectly closed tag throws Cannot set property endSourceSpan of null May 13, 2016
@mcwienczek
Copy link

@mcwienczek mcwienczek commented May 22, 2016

Same still happening to me on 2.0.0-rc.1. When you have too many closing tags this might happen. Only because of this issue I was able to quickly fix the real problem.

@RolfVeinoeSorensen
Copy link

@RolfVeinoeSorensen RolfVeinoeSorensen commented May 31, 2016

I am using umd so I had to alter compiler.umd.js with the fix suggested by bananenmannfrau

@ericmartinezr
Copy link
Contributor Author

@ericmartinezr ericmartinezr commented Jun 3, 2016

@bananenmannfrau what about sending a PR? :D It would be nice to have this fixed by the next RC

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 8, 2019

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.