Tidy 16

From Htmlpedia
Jump to: navigation, search

Tidy: missing quote mark for attribute value

Cause:

The quote mark that opens an attribute value is not closed before the parser encounters a <, >, or balancing " or '.

Example: absent quote mark

Bad<img src="janedoe.png" alt="Jane Doe />
Good<img src="janedoe.png" alt="Jane Doe" />

Example: reserved character in attribute value

Bad<img src="example.png" alt="" title="Example of the <code> element" />
Good<img src="example.png" alt="" title="Example of the &lt;code&gt; element" />

Example: unbalanced quotes

Bad<img src='johndoecar.png' alt='John Doe's car' />
Good<img src='johndoecar.png' alt='John Doe&#39;s car' />
or
Good<img src="johndoecar.png" alt="John Doe's car" />

Solution:

Add any missing quote marks, and be sure reserved characters are escaped properly.

This may be tricky in dynamically generated markup. Some languages provide a tidy function, e.g. PHP htmlspecialchars. In Javascript, it is necessary to include a routine to search and replace reserved characters.

References: