[Rt-commit] rt branch, 4.4/style-custom-field-name, created. rt-4.4.2-30-g58f5b5fb9

Maureen Mirville maureen at bestpractical.com
Fri Aug 10 06:48:05 EDT 2018


The branch, 4.4/style-custom-field-name has been created
        at  58f5b5fb9053a7ae2cb58dade5270a1d37ee4398 (commit)

- Log -----------------------------------------------------------------
commit af71ccfd18f2a2fefacce01b8ae720db96b0841a
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date:   Mon Jul 31 14:43:31 2017 -0400

    Target style at custom field name
    
    Custom fields may be styled using custom field name as class selector.

diff --git a/share/html/Elements/ShowCustomFields b/share/html/Elements/ShowCustomFields
index 2f7d2aefd..418fd61f6 100644
--- a/share/html/Elements/ShowCustomFields
+++ b/share/html/Elements/ShowCustomFields
@@ -54,9 +54,13 @@
 % my $Values = $Object->CustomFieldValues( $CustomField->Id );
 % my $count = $Values->Count;
 % next if $HideEmpty and not $count;
+% my $CustomFieldName = $CustomField->Name;
+%#The following substitution replaces all non-ID_Continue characters with a dash character. The ID_Continue Unicode property was chosen because it (combined with ID_Start) is meant for variable names. ID_Continue includes characters suitable for use in CSS-class names (even non-Latin ones, to support non-English custom field names) and excludes syntactic characters that are not (such as whitespace characters).
+% $CustomFieldName =~ s/\P{ID_Continue}+/-/g;
 % my @classes = (
 %   'custom-field',
 %   'custom-field-'.$CustomField->id,
+%   'custom-field-'.$CustomFieldName,
 % );
 % push @classes, 'unset-field' if not $count;
 % $m->callback( CallbackName => 'ModifyFieldClasses', CustomField => $CustomField,

commit 58f5b5fb9053a7ae2cb58dade5270a1d37ee4398
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date:   Thu Aug 17 14:51:18 2017 -0400

    Add tests for CF class selector
    
    Tests added to verify that each custom field name has a
    corresponding class selector with invalid CSS characters escaped.

diff --git a/t/web/css.t b/t/web/css.t
new file mode 100644
index 000000000..f2c112483
--- /dev/null
+++ b/t/web/css.t
@@ -0,0 +1,39 @@
+use utf8;
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+# Each custom field must have a corresponding class selector with invalid characters escaped
+{
+    my( $baseurl, $m ) = RT::Test->started_ok;
+    ok( $m->login, 'logged in' );
+
+    my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+
+    ok ( $m->goto_create_ticket( $queue ) );
+    $m->form_name( 'TicketCreate' );
+    $m->field( Subject => 'Test Ticket' );
+    $m->submit;
+
+    $m->follow_link_ok( { id => 'admin-custom-fields' } );
+    $m->follow_link_ok( { id => 'page-create' } );
+    $m->form_name( 'ModifyCustomField' );
+    $m->field( 'Name' => 'test class% م 例 name' );
+    $m->click( 'Update' );
+    my ( $cf_id ) = ( $m->uri =~ /id=(\d+)/ );
+
+    $m->follow_link_ok( { text => 'Applies to' } );
+    $m->submit_form_ok( {
+        with_fields => {
+            "AddCustomField-$cf_id" => 0,
+        },
+        button => 'UpdateObjs',
+    }, 'Added new custom field globally' );
+
+    my $res = $m->get( $baseurl . '/Ticket/Display.html?id=1' );
+    my $element = $m->dom->at( ".custom-field-$cf_id" );
+    like( $element->attr( 'class' ), qr/test-class-م-例-name/, 'Class selector added to custom field, invalid characters have been escaped' );
+}
+
+done_testing();

-----------------------------------------------------------------------


More information about the rt-commit mailing list