homebrewery
homebrewery copied to clipboard
emit tag classname as lowercase on userpage
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
Philosophically, there should also be an intervention in some middleware to "correct" data errors on saving/loading. That's more complicated though.
return <span key={idx} className={matches[1]?.toLowerCase()} onClick={()=>{this.updateFilter('tag', tag);}}>{matches[2]}</span>;
Another point is that tags are not trimmed before being set, so a
!== a
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.
While stray spaces on tags do cause problems elswhere, they don't cause a problem with class names as
class=" system"
is == toclass=" system"
as far as html/css cares.
I know, just saying we should trim when inputing tags