alixaxel / phunction

Small and carefully designed PHP 5.2+ HMVC framework.
//github.com/alixaxel/phunction/
MIT License
105 stars 10 forks source link

Remove empty attributes #4

Closed xeoncross closed 13 years ago

xeoncross commented 13 years ago

I was just checking out the nice updates you've made to Purify when I noticed that empty attributes are still allowed on DOM elements. You might want to remove them since they just waste space.

Add this on line 1794.

if( !  $attribute->value)
{
    $html->removeAttributeNode($attribute);
    continue;
}
alixaxel commented 13 years ago

Hi David, thanks for the feedback! I thought about doing that but take the following XHTML snippet for instance:

<input type="checkbox" disabled="disabled" checked="checked" />

It's the exact HTML (4 and 5) equivalent of:

<input type="checkbox" disabled checked>

In HTML, attributes with no values are considered valid, removing them could cause some problems (depending on the whitelist).

xeoncross commented 13 years ago

Right you are sir!

The main thing I was trying to fix is empty class="" or id="" attributes taking up extra space. I guess it really don't matter though.

alixaxel commented 13 years ago

I would like that too, but the DOMAttr class has no way of distinguishing between empty and absent attributes.

Without compiling a list of attributes that can have no value, I don't see any other way of accomplish that goal. Maybe Tidy could do something here, but I've had bad experiences with it in the past, specially with HTML 5 and HTML partials.