[rt-users] maintainably tagging custom fields for CSS

Nicholas Clark nick at ccl4.org
Wed Aug 15 13:49:05 EDT 2007

On Tue, Aug 14, 2007 at 12:22:13PM +0100, Nicholas Clark wrote:
> On Tue, Aug 14, 2007 at 10:01:08AM +0200, Espen Wiborg wrote:
> > (Once more, to the list this time.)
> > 
> > Jesse Vincent <jesse at bestpractical.com> writes:
> > > On Mon, Aug 13, 2007 at 05:36:50PM +0100, Nicholas Clark wrote:
> > >> Is there a good way to reliably map text outside the range of legal
> > >> identifiers into that range, without having too many collisions?
> > >> 
> > >> (I realise that this might sound like "solve the halting problem" or "integer
> > >> knapsack" but I think we need "good" rather than "perfect")
> > > See if URL-encoding meets the spec?
> > 
> > You'd have to strip out the percent signs; they're not allowed in XML
> > IDs.  Other than that, URL-encoding sounds like the best bet.
> Thanks. I had no idea about that subtlety of the the XML spec.
> But I wonder, why do we need to URL encode them? If the RT admin is naming
> custom fields with characters outside US-ASCII, then the HTML generated
> will already contain Unicode characters, so why not keep (acceptable) Unicode
> characters in the values given to the ID tags. If I understand it correctly,
> the XML 1.1 spec allows most any alphanumeric character in names:
>   http://www.w3.org/TR/xml11/#sec-common-syn
> so I think it would be possible to produce valid identifiers simply by
> stripping out all characters not valid in names. (whitespace, punctuation,
> etc). Names will clash if someone configures two custom fields with names
> that differ only in punctuation or whitespace, but in that case they pretty
> much deserve what they are getting :-)

Jesse, on IRC, has the alternative suggestion of using a class. It has the
advantage that it won't be invalid XML if two fields happen to end up with
the same ID. But what's going to be impractical in class names for CSS?

I did this to map & and "

diff -p -u -r1.1.1.2 EditCustomFields
--- html/Ticket/Elements/EditCustomFields       1 Aug 2007 15:56:47 -0000
+++ html/Ticket/Elements/EditCustomFields       15 Aug 2007 17:42:38 -0000
@@ -62,7 +62,10 @@
 % }
 % $i++;
-  <tr id="CF-<%$CustomField->id%>-EditRow">
+% my $class = $CustomField->Name;
+% $class =~ s/&/&/gs;
+% $class =~ s/"/"/gs;
+  <tr id="CF-<%$CustomField->id%>-EditRow" class="<% $class %>">
     <td class="labeltop">
       <b><%$CustomField->Name%></b><br />

But my HTML can be:

<tr id="CF-9-EditRow" class="What next">

Is that space in the class name going to be a problem?

What's a sensible restriction on what can go in? Is there a CSS grammar for
what is(n't) valid in a class name?

Nicholas Clark

More information about the rt-users mailing list