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

"<" symbol not parsed as text when common browsers do it #72

Open
davidfoliveira opened this issue Mar 23, 2015 · 2 comments
Open

"<" symbol not parsed as text when common browsers do it #72

davidfoliveira opened this issue Mar 23, 2015 · 2 comments

Comments

@davidfoliveira
Copy link

If a text on the HTML has a "<", the text is not parsed after that.
Example: <title>We <3cupcakes</title>

The "<3cupcakes" is interpreted like being a tag when common browsers parse it like text.

@davidfoliveira
Copy link
Author

Suggestion of patch.

diff -rc node_modules/htmlparser/lib/htmlparser.js node_modules/new_htmlparser/lib/htmlparser.js
*** node_modules/htmlparser/lib/htmlparser.js   Thu Apr 12 19:04:06 2012
--- node_modules/new_htmlparser/lib/htmlparser.js   Tue Mar 24 01:11:47 2015
***************
*** 219,225 ****
            this._next = Parser._reTags.lastIndex - 1;
            var tagSep = this._buffer.charAt(this._next); //The currently found tag marker
            var rawData = this._buffer.substring(this._current, this._next); //The next chunk of data to parse
!   
            //A new element to eventually be appended to the element list
            var element = {
                  raw: rawData
--- 219,238 ----
            this._next = Parser._reTags.lastIndex - 1;
            var tagSep = this._buffer.charAt(this._next); //The currently found tag marker
            var rawData = this._buffer.substring(this._current, this._next); //The next chunk of data to parse
!           // A tag element that doesn't finish with a '>' ? Naah.. this is text
!           if ( this._parseState == ElementType.Tag && tagSep != ">" && rawData.substr(0,3) != "!--" ) {
!               var prevElement = (this._elements.length > 0) ? this._elements[this._elements.length-1] : null;
!               if ( prevElement && prevElement.type == ElementType.Text ) {
!                   prevElement.raw += '<'+rawData;
!                   prevElement.data += '<'+rawData;
!                   this._current = this._next+1;
!                   continue;
!               }
!               else {
!                   this._parseState = ElementType.Text;
!                   rawData = '<'+rawData;
!               }
!           }
            //A new element to eventually be appended to the element list
            var element = {
                  raw: rawData

@eranimo
Copy link

eranimo commented Nov 18, 2015

Can you submit a PR?

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

2 participants