]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 525025: Custom field names having UTF8-characters in them crash Bugzilla - Patch...
authorlpsolit%gmail.com <>
Sun, 1 Nov 2009 19:49:24 +0000 (19:49 +0000)
committerlpsolit%gmail.com <>
Sun, 1 Nov 2009 19:49:24 +0000 (19:49 +0000)
Bugzilla/Field.pm
Bugzilla/Install/DB.pm

index 077c67e20e6de5b736e7b76ed24df8758fb0b73c..7b1569c520209552360a0e70bfd92f81295541a9 100644 (file)
@@ -273,7 +273,7 @@ sub _check_name {
     my $name_regex = qr/^[\w\.]+$/;
     # Custom fields have more restrictive name requirements than
     # standard fields.
-    $name_regex = qr/^\w+$/ if $is_custom;
+    $name_regex = qr/^[a-zA-Z0-9_]+$/ if $is_custom;
     # Custom fields can't be named just "cf_", and there is no normal
     # field named just "cf_".
     ($name =~ $name_regex && $name ne "cf_")
index df62960560316f26e9e17635f1a695b7f71fb47e..51d2582274f77c69a48f57a3c113faa5ac9751fe 100644 (file)
@@ -583,6 +583,9 @@ sub update_table_definitions {
     # 2009-09-28 LpSolit@gmail.com - Bug 399073
     _fix_logincookies_ipaddr();
 
+    # 2009-11-01 LpSolit@gmail.com - Bug 525025
+    _fix_invalid_custom_field_names();
+
     ################################################################
     # New --TABLE-- changes should go *** A B O V E *** this point #
     ################################################################
@@ -3219,6 +3222,19 @@ sub _fix_logincookies_ipaddr {
              undef, '0.0.0.0');
 }
 
+sub _fix_invalid_custom_field_names {
+    my @fields = Bugzilla->get_fields({ custom => 1 });
+
+    foreach my $field (@fields) {
+        next if $field->name =~ /^[a-zA-Z0-9_]+$/;
+        # The field name is illegal and can break the DB. Kill the field!
+        $field->set_obsolete(1);
+        eval { $field->remove_from_db(); };
+        print "Removing custom field '" . $field->name . "' (illegal name)... ";
+        print $@ ? "failed\n$@\n" : "succeeded\n";
+    }
+}
+
 1;
 
 __END__