ec-europa / atomium

The very base theme
https://drupal.org/project/atomium
European Union Public License 1.1
9 stars 5 forks source link

Attributes behavior for empty string or space-only values. #170

Open donquixote opened 6 years ago

donquixote commented 6 years ago

Currently, the Attributes class is not really designed for attribute values that are empty strings, or that contain spaces.

It might accidentally do what we expect in many cases, but it is not really guaranteed.

Different nature of attributes

The main problem is the duality of the attributes concept:

I think we currently don't and we should not make a hardcoded distinction based on the attribute name.

Instead, if we need to make a distinction (which is to be discussed), we should make it based on the method being called, the arguments passed to it, and the value already in the attribute.

Storage format

The storage proposed in #130 works for all cases:

However this storage does not tell us whether an attribute is intentionally single-value or just an array-like attribute which incidentally has only one fragment.

The storage for empty string is not really clear yet, it would be one of these:

Modifier methods

Should any methods explode strings passed to them?

Proposed solution

Whenever a method is called that sets a single string value, it will do just that. No trimming, no exploding.

A method that adds fragments, e.g. setAttribute('class', ['a', 'b', 'c']) or append('class', 'x') should not explode its values either.

Or should it?

@drupol

drupol commented 6 years ago

I do agree, we should not explode the values.

donquixote commented 6 years ago

Also not trim, right?