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

(next_tag || "").match is not a function #1202

Closed
ddehghan opened this issue Jun 4, 2017 · 3 comments
Closed

(next_tag || "").match is not a function #1202

ddehghan opened this issue Jun 4, 2017 · 3 comments

Comments

@ddehghan
Copy link

ddehghan commented Jun 4, 2017

We are getting an exception in our production code on this like of code.

TypeError : (n || "").match is not a function

https://github.com/beautify-web/js-beautify/blob/56fac25c86e352d67e6250966695e617d58e92d8/js/lib/beautify-html.js

                //at this point we have an  tag; is its first child something we want to remain
                //unformatted?
                var next_tag = this.get_tag(true /* peek. */ );

                // test next_tag to see if it is just html tag (no external content)
                var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/);

After debugging it we think it happens when for some reason next_tag returns as a non string.

Our code:

let o: HTMLBeautifyOptions = {};
                o.indent_size = 4;
                o.wrap_line_length = 120;
                o.indent_inner_html = true;
                o.wrap_attributes = "force";
html_beautify(this._element.outerHTML, o)

Here are some example cases that caused exception:

<a class="js-open-move-from-header" href="#">5A - IN-SPRINT TESTING</a>

<a href="http://www.realitica.com/hr/listing/1331556" onclick="reaClickTrack('MwpjYntU2YEro%2F2wGLcTtqdyvNyF%2F%2BGwUZTg5sm6tXoHjcp9c0y2elZUtDvq3QvxCM%2FHrploJR08B2sm5PDAXrofetCjdvdAGLt6DuT56zw%3D');" style="text-decoration: none;color:black;" >Na prodaju LUX trosoban stan 136 m2 u novogradnji,u centru Podgorice.Zgrada je izuzetno kvalitetne gradnje,završena je 2015. godine,a nalazi se ispod Gorice - tik uz buduću Njemačk...</a>

<a" >9</a">


<a href="javascript:;" id="_h_url_paid_pro3" onmousedown="_h_url_click_paid_pro(this);" rel="nofollow" class="pro-title" itemprop="name">WA GlassKote</a>


<a href="/b/yergey-brewing-a-beer-has-no-name/1745600" >"A Beer Has No Name"</a>


<a class="wine-suggest-link" href="https://www.wine-searcher.com/find/la+vina+ardanza+rsrv+doca+rioja+alta+spain">La Rioja Alta Vina Ardanza Reserva, Rioja DOCa, Spain</a>






All the exceptions we are getting are form a single A tag.

@bitwiseman bitwiseman added this to the v1.7.x milestone Jun 5, 2017
@ddehghan
Copy link
Author

more debugging info: given the test cases above that I mentioned the next_tag is an array so (next_tag || "") fails because it expects a string.

@ddehghan
Copy link
Author

FYI This bug is still happening.

bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Jan 23, 2018
@bitwiseman
Copy link
Member

Thanks for the reminder. This will be in the next release.

@bitwiseman bitwiseman modified the milestones: v1.7.x, v1.7.6 May 21, 2018
@bitwiseman bitwiseman modified the milestones: v1.8.0-rc2, 1.8.0 Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants