[Rt-commit] rt branch, 4.4/style-custom-field-name, created. rt-4.4.2-30-g6b600ca
Maureen Mirville
maureen at bestpractical.com
Tue Aug 29 15:32:31 EDT 2017
The branch, 4.4/style-custom-field-name has been created
at 6b600ca3e34a733ccf73df660f9a5c7998ce6cf0 (commit)
- Log -----------------------------------------------------------------
commit 6713f24f603eb6c330641a99dfcf5b702d536268
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 2f7d2ae..2408386 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 line ensures invalid characters are removed (supports world languages).
+% $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 6b600ca3e34a733ccf73df660f9a5c7998ce6cf0
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/share/html/Elements/ShowCustomFields b/share/html/Elements/ShowCustomFields
index 2408386..264bcdf 100644
--- a/share/html/Elements/ShowCustomFields
+++ b/share/html/Elements/ShowCustomFields
@@ -55,7 +55,7 @@
% my $count = $Values->Count;
% next if $HideEmpty and not $count;
% my $CustomFieldName = $CustomField->Name;
-%# The following line ensures invalid characters are removed (supports world languages).
+%#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',
diff --git a/t/customfields/api.t b/t/customfields/api.t
index 873503c..928e435 100644
--- a/t/customfields/api.t
+++ b/t/customfields/api.t
@@ -1,10 +1,11 @@
-
+use utf8;
use strict;
use warnings FATAL => 'all';
-use RT::Test nodata => 1, tests => 157;
+use RT::Test tests => undef;
use Test::Warn;
+use CGI;
# Before we get going, ditch all object_cfs; this will remove
# all custom fields systemwide;
@@ -253,7 +254,7 @@ my $all_classes = RT::Class->new( RT->SystemUser );
is($msg, 'Globally added custom field custom_field_0.', "Adding custom field globally produces appropriate message");
($status, $msg) = $custom_field->RemoveFromObject( $all_queues );
- is($msg, 'Globally removed custom field custom_field_0.', "Rmeoving custom field globally produces appropriate message");
+ is($msg, 'Globally removed custom field custom_field_0.', "Removing custom field globally produces appropriate message");
}
# Ticket CustomField Message Test
@@ -298,3 +299,29 @@ my $all_classes = RT::Class->new( RT->SystemUser );
is($msg, 'Globally removed custom field custom_field_2.', "Removing custom field globally produces appropriate message");
}
+# 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');
+
+ $m->get_ok($baseurl . '/Admin/CustomFields/Modify.html?Create=1');
+ $m->form_name('ModifyCustomField');
+ $m->field('Name' => 'test class% م 例 name');
+ $m->click('Update');
+ my $url = $m->uri;
+ my $cgi = CGI->new($url);
+ my $cf_id = $cgi->param('id');
+
+ $m->get_ok($baseurl . "/Admin/CustomFields/Objects.html?id=$cf_id");
+ $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