homebrewery icon indicating copy to clipboard operation
homebrewery copied to clipboard

emit tag classname as lowercase on userpage

Open ericscheid opened this issue 1 year ago • 5 comments

Tags can be entered when enditing a brew as <tag-type>:<tag-name>, where <tag-type> is a limited enumerated set of values. That tag data-entry UI also enforces lowercase for <tag-type>.

It is possible however to circumvent that UI (e.g. edit the google-doc source).

The <tag-type> is emitted on the userpage by setting the className of the tag display element: <span class="system">C&C</span>. This is so different tag-types can be styled differently (e.g. "system" tags in blue, untyped tags as yellow).

However, css classnames are case sensitive. We should enforce the schema design constraint not only in the data-entry UI, but also in the emitting of tags onto the userpage. (Postel's Law)

The relevant code to fix is on line 132 here:

https://github.com/naturalcrit/homebrewery/blob/be72b029bfd267507b1d784cdfc32d5dc62c3c88/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx#L127-L134

ericscheid avatar Dec 03 '23 03:12 ericscheid

Philosophically, there should also be an intervention in some middleware to "correct" data errors on saving/loading. That's more complicated though.

ericscheid avatar Dec 03 '23 03:12 ericscheid

return <span key={idx} className={matches[1]?.toLowerCase()} onClick={()=>{this.updateFilter('tag', tag);}}>{matches[2]}</span>;

G-Ambatte avatar Dec 03 '23 03:12 G-Ambatte

Another point is that tags are not trimmed before being set, so a !== a

5e-Cleric avatar Feb 06 '24 20:02 5e-Cleric

While stray spaces on tags do cause problems elswhere, they don't cause a problem with class names as class=" system" is == to class=" system" as far as html/css cares.

ericscheid avatar Feb 06 '24 21:02 ericscheid

While stray spaces on tags do cause problems elswhere, they don't cause a problem with class names as class=" system" is == to class=" system" as far as html/css cares.

I know, just saying we should trim when inputing tags

5e-Cleric avatar Feb 06 '24 22:02 5e-Cleric