WordPress / wp-lazy-loading

Feature plugin for testing and experimenting with the "loading" HTML attribute.

Home Page:https://wordpress.org/plugins/wp-lazy-loading/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regex: no space after previous attribute

superpoincare opened this issue · comments

I suppose something like

<img src="image.jpg" alt="foobar"loading=lazy height="10" width="10">

is a valid html.

Notice no space before loading

But the plugin still adds a loading="lazy" attribute

so the output looks like:

<img loading="lazy" src="image.jpg" alt="foobar"loading=lazy height="10" width="10">

I suppose nobody would not add a space before writing an attribute but it's still valid, so I am not sure if it has to be checked, but reporting anyway.

This happens because the code checks for a whitespace before loading

https://github.com/WordPress/wp-lazy-loading/blob/master/wp-lazy-loading.php#L143

Thanks for bringing this up.

I suppose something like <img src="image.jpg" alt="foobar"loading=lazy height="10" width="10"> is a valid html.

Not valid according to WHATWG: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2.

The exact text is: "If an attribute using the double-quoted attribute syntax is to be followed by another attribute, then there must be ASCII whitespace separating the two.". The same is true for all other attribute definitions, single quote, no quotes, no value.

It is also not possible to add such HTML by using either the block or the classic editor in WP. Even if such malformed HTML is pasted, it is automatically corrected.