js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

Invalid attribute name should be ignored

Open Janpot opened this issue 7 years ago • 2 comments

Description

Let me start off by noting that this issue is about invalid html. It's a bit of an edge case but let me explain how I obtain this html. I'm trying to beautify a html string that comes from a DOM element that I don't control. I use element.innerHTML and feed the result into the html beautifier. Unfortunately some invalid input still produces a working DOM. example:

new DOMParser().parseFromString(`<div "><div>hello</div></div>`, 'text/html').body.innerHTML
// <div "=""><div>hello</div></div>

If I understand correctly, parsers should just ignore invalid attribute names and continue parsing.

Input

The code looked like this before beautification:

<div "=""><div>hello</div></div>

<div "><div>hello</div></div>

Expected Output

The code should have looked like this after beautification:

<div "="">
  <div>hello</div>
</div>

<div ">
  <div>hello</div>
</div>

Actual Output

The code actually looked like this after beautification:

<div "=" "><div>hello</div></div>

<div "><div>hello</div></div>

Settings

Default

Janpot avatar Mar 31 '17 09:03 Janpot

ever thought about using htmlparser2?

Janpot avatar Mar 31 '17 14:03 Janpot

@Janpot - We've tried to use minimal node-specific dependencies in order to support both javascript and python implementations with as much of the codebase being the same as possible.

We don't have a python implementation for html at this time, but we don't want to block that path in the future.

bitwiseman avatar Mar 31 '17 20:03 bitwiseman