[Rt-devel] [PATCH] RT 3.6.1 CLI--how to pass in a newline

Jim Brandt cbrandt at buffalo.edu
Thu Sep 28 13:40:02 EDT 2006


The patch was easy enough to generate, so it's included below. It allows 
you to pass in a string with newlines via 'rt create'.

I was able to run all of lib/t/regression/26command_line.t with this in 
place and it didn't appear to break anything. I tried to create a few 
new tests for this case, but it turned out to be difficult to pass a 
command with a newline through Test::Expect.

It allows newlines for other fields as well, but it doesn't seem to 
break things. I tried with subject and RT seems to handle it correctly. 
It does seem to retain the '\' and put it at the end of the subject 
string. Maybe it would be better to allow newlines only for fields that 
allow them?

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

--- bin/rt      2006-09-28 08:53:43.000000000 -0400
+++ /opt/rt3/bin/rt     2006-09-25 10:48:09.000000000 -0400
@@ -388,7 +388,7 @@
          elsif (/^set$/i) {
              my $vars = 0;

-            while (@ARGV && $ARGV[0] =~ /^($field)([+-]?=)(.*)$/xms) {
+            while (@ARGV && $ARGV[0] =~ /^($field)([+-]?=)(.*)$/) {
                  my ($key, $op, $val) = ($1, $2, $3);
                  my $hash = ($op eq '=') ? \%set : ($op =~ /^\+/) ? 
\%add : \%del;



Jim Brandt wrote:
> Note: original question posted on the RT users list. This is a follow-up
> and possible solution.
> 
> Thanks to der Mouse for the shell tutorial. :)
> 
> I tried his suggestion and while I finally came to terms with my shell,
> it confused the rt CLI. I was getting this with newlines:
> 
> rt: edit: No variables to set.
> 
> I messed around a bit and found that sticking the 'xms' at the end of
> the regex seemed to make it work the way I wanted:
> 
>         elsif (/^set$/i) {
>             my $vars = 0;
> 
> --->        while (@ARGV && $ARGV[0] =~ /^($field)([+-]?=)(.*)$/xms) {
>                 my ($key, $op, $val) = ($1, $2, $3);
> 
> What I don't know is if this causes other un-wanted side effects with 
> multi-line commands, thus my post to the dev list. Would this be a 
> desired or worthwhile patch?
> 
> Thanks,
> Jim
> 
> 
> der Mouse wrote:
>>> So you're thinking I need to trick the shell into sending the proper
>>> newline character?
>>
>> Yes, though I'm not sure "trick" is the best word. :-)
>>
>>> I use tcsh,
>>
>> Try
>> % echo 'foo\
>> bar'
>>
>> that is, a real newline, inside single quotes, but also backslashed.
>> That works in all csh derivatives I've run into, including a real tcsh
>> (6.13.00) I happen to have access to.  (I don't use tcsh myself.)
>>
>> /~\ The ASCII                der Mouse
>> \ / Ribbon Campaign
>>  X  Against HTML           mouse at rodents.montreal.qc.ca
>> / \ Email!         7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
> 

-- 
Jim Brandt
Administrative Computing Services
University at Buffalo



More information about the Rt-devel mailing list