Skip Menu |

This queue is for tickets about the RT-Client-REST CPAN distribution.

Report information
The Basics
Id: 42391
Status: resolved
Priority: 0/
Queue: RT-Client-REST

People
Owner: jpierce [...] cpan.org
Requestors: drew [...] drewtaylor.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.37
Fixed in: (no value)



Subject: Form changed for Custom Fields in 3.8
I saw ticket 39868 which described the same problem I'm having. But I feel my patch is more complete because it more closely emulates the behavior of RT. Basically, custom_field_spec() returns a regex which is used to parse the form for Custom Field values. It nicely handles both old and new style forms. Tests pass, though the suite doesn't have a test to actually test CF setting/getting. I may give that a shot this week as well... custom_field_spec() is copied verbatim from RT::Interface::REST. I think the licenses should be compatible. But if not we can certainly take the spirit of the regex. :-) to_form() is ok because RT is likely to support both CF naming styles for a long time. --Drew Bonnie:REST dtaylor$ diff -u Object.pm.orig Object.pm --- Object.pm.orig 2009-01-13 22:36:57.000000000 +0000 +++ Object.pm 2009-01-13 22:45:40.000000000 +0000 @@ -401,6 +401,28 @@ return \%hash; } +=item custom_field_spec + +Regex for parsing custom fields from form received from RT server. +Handles both new style of "CF.$name" and old style of "CF-". +Copied from RT::Interface::REST.pm + +=cut + +sub custom_field_spec { + my $self = shift; + my $capture = shift; + + my $CF_char = '[\sa-z0-9_ :()/-]'; + my $CF_name = $CF_char . '+'; + $CF_name = '(' . $CF_name . ')' if $capture; + + my $new_style = 'CF\.\{'.$CF_name.'\}'; + my $old_style = 'C(?:ustom)?F(?:ield)?-'.$CF_name; + + return '(?i:' . join('|', $new_style, $old_style) . ')'; +} + =item from_form Set object's attributes from form received from RT server. @@ -435,13 +457,15 @@ } # Now set attbibutes: + my $cf_spec = $self->custom_field_spec(1); while (my ($key, $value) = each(%$hash)) { - if ($key =~ s/^cf-//) { # Handle custom fields. + if ($key =~ /^$cf_spec/) { # Handle custom fields. + my $name = $1 || $2; # new style is $1 and old style is $2 if ($value =~ /,/) { # OK, this is questionable. $value = [ split(/\s*,\s*/, $value) ]; } - $self->cf($key, $value); + $self->cf($name, $value); next; }
Necessary changes were more extensive than just your patch, or #39868's. Feel free to test pre-.40 from: http://code.google.com/p/rt-client-rest/source/checkout
Hello, We've released a new version of RT::Client::REST to CPAN wich should have the issue you reported fixed. Please come back to us if you feel this issue is not solved correctly. You can find the new version at http://search.cpan.org/~jlmartin/RT-Client-REST-0.4/ Thanks, Jose Luis Martinez RT::Client::REST Co-MAINT