[Rt-commit] rt branch, 4.0/rest-multiple-values-cfs-on-ticket-creation, created. rt-4.0.22-26-g2e2db2e

? sunnavy sunnavy at bestpractical.com
Wed Jan 14 11:44:33 EST 2015


The branch, 4.0/rest-multiple-values-cfs-on-ticket-creation has been created
        at  2e2db2ef9b2c2c05ae4cf047a5a6d18ed0f361be (commit)

- Log -----------------------------------------------------------------
commit 2e2db2ef9b2c2c05ae4cf047a5a6d18ed0f361be
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jan 14 21:22:17 2015 +0800

    cf multiple values support on restful ticket creation
    
    interestingly that we kina supported it on server side, and it requires the
    format like this(i.e. multiple rows, see also t/web/rest.t:172):
    
        CF.{foo}: bar
        CF.{foo}: baz
    
    but bin/rt automatically converts the format above to:
    
        CF.{foo}: bar,baz
    
    before submitting to server, so it actually doesn't work with bin/rt
    
    now we support the same comma seprated format like what we do on edit

diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index 33a8935..24b1829 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -163,7 +163,52 @@ else {
                     delete $data{$k};
                     next;
                 }
-                $v{"CustomField-".$cf->Id()} = delete $data{$k};
+                my $val = delete $data{$k};
+                next unless defined $val && length $val;
+                if ( $cf->SingleValue ) {
+                    $v{"CustomField-".$cf->Id()} = $val;
+                }
+                else {
+                    my @new;
+
+                    # back compatbility
+                    # to support multiple lines format:
+                    # CF.{foo}: bar
+                    # CF.{foo}: baz
+                    $val = join ',', @$val if ref $val eq 'ARRAY';
+
+                    my ( $a, $b ) = split /\s*,\s*/, $val, 2;
+                    while ($a) {
+                        no warnings 'uninitialized';
+                        if ( $a =~ /^'/ ) {
+                            my $s = $a;
+                            while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
+                                            && $a =~ /(\\)+'$/ ) ) {
+                                ( $a, $b ) = split /\s*,\s*/, $b, 2;
+                                $s .= ',' . $a;
+                            }
+                            $s =~ s/^'//;
+                            $s =~ s/'$//;
+                            $s =~ s/\\'/'/g;
+                            push @new, $s;
+                        }
+                        elsif ( $a =~ /^q\{/ ) {
+                            my $s = $a;
+                            while ( $a !~ /\}$/ ) {
+                                ( $a, $b ) = split /\s*,\s*/, $b, 2;
+                                $s .= ',' . $a;
+                            }
+                            $s =~ s/^q\{//;
+                            $s =~ s/\}//;
+                            push @new, $s;
+                        }
+                        else {
+                            push @new, $a;
+                        }
+                        ( $a, $b ) = split /\s*,\s*/, $b, 2;
+                    }
+                    $v{"CustomField-".$cf->Id()} = \@new;
+                }
             }
             elsif (lc $k eq 'text') {
                 $text = delete $data{$k};

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


More information about the rt-commit mailing list