Summary: | ASTERISK-10460: CUT() won't let you cut on a carriage return | ||
Reporter: | Leif Madsen (lmadsen) | Labels: | |
Date Opened: | 2007-10-05 17:47:19 | Date Closed: | 2007-10-25 19:14:34 |
Priority: | Minor | Regression? | No |
Status: | Closed/Complete | Components: | Functions/func_cut |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ||
Description: | I'm trying to read in a file into the dialplan, and then parse each line of the file with the CUT() function, but unfortunately have been unable to make it work. I've tried: Set(LINE=${CUT(ENVELOPE,\n,1)}) Set(LINE=${CUT(ENVELOPE,\\n,1)}) Set(LINE=${CUT(ENVELOPE,\\\n,1)}) Set(LINE=${CUT(ENVELOPE,\r\n,1)}) Set(LINE=${CUT(ENVELOPE,\\r\\n,1)}) Set(LINE=${CUT(ENVELOPE,\\\r\\\n,1)}) But it seems it just cut on the literal letter ('r' or 'n' in this case). ****** ADDITIONAL INFORMATION ****** A sample dialplan: exten => 8502,1,Answer() exten => 8502,n,ReadFile(ENVELOPE=/var/spool/asterisk/voicemail/default/100/INBOX/msg0000.txt) exten => 8502,n,Set(X=1) exten => 8502,n,While($[${EXISTS(${CUT(ENVELOPE,\n,${X})})}]) exten => 8502,n,Verbose(1|${CUT(ENVELOPE,\n,${X})}) exten => 8502,n,Set(X=$[${X} + 1]) exten => 8502,n,EndWhile() | ||
Comments: | By: Mark Michelson (mmichelson) 2007-10-05 23:32:54 Interesting...have you attempted this in trunk? A cursory read of the code suggests that it is taken care of in trunk. I know this won't fix things in 1.4, but it will at least give a good idea of how to backport the fix. By: Leif Madsen (lmadsen) 2007-10-06 03:08:09 FYI for anyone else who comes across this in the meantime, I've developed a work around: exten => 8,n,Set(DATA=${SHELL(tr "\\\n"\, "&" < ${PATH_TO_VM}/${VM_CTX}/${MAILBOX}/INBOX/msg${MSGNUM}.txt \| cut -d \\\& -f ${LINE_NUMBER})}) By: Leif Madsen (lmadsen) 2007-10-06 03:08:41 Sorry, I haven't tried in trunk yet. I'll give it a shot tomorrow maybe. By: Tilghman Lesher (tilghman) 2007-10-06 09:26:24 My thought was on applying the fix to trunk was that it was an additional feature, and indeed, CURL with multiple lines was the reason why. Note that if the output really is line-terminated with "\r\n", CUT will not perform that way, even in trunk, as it accepts a single character delimiter only. By: Leif Madsen (lmadsen) 2007-10-06 09:39:02 And that should be fine because these files I'm pretty sure are just going to be terminated with \n (Asterisk builds this file). In this case it does seem like a bug to me... but I'm not sure how invasive the change is. Do we need to ask Russell if this is a bug, or a feature request? By: Leif Madsen (lmadsen) 2007-10-07 11:11:38 I talked to Russell last night on IRC, and he said he was fine with the change in trunk to accept the \n as a delimiter to go back into 1.4. Unfortunately I don't have the chops to backport it myself. By: Digium Subversion (svnbot) 2007-10-25 17:51:33 Repository: asterisk Revision: 87067 U branches/1.4/funcs/func_cut.c ------------------------------------------------------------------------ r87067 | tilghman | 2007-10-25 17:51:32 -0500 (Thu, 25 Oct 2007) | 4 lines Backport alternate encoding of newline delimiters from trunk to 1.4, as approved by Russell Reported by blitzrage Closes issue ASTERISK-10460 ------------------------------------------------------------------------ By: Digium Subversion (svnbot) 2007-10-25 19:14:34 Repository: asterisk Revision: 87104 _U trunk/ ------------------------------------------------------------------------ r87104 | tilghman | 2007-10-25 19:14:34 -0500 (Thu, 25 Oct 2007) | 11 lines Blocked revisions 87067 via svnmerge ........ r87067 | tilghman | 2007-10-25 17:53:06 -0500 (Thu, 25 Oct 2007) | 4 lines Backport alternate encoding of newline delimiters from trunk to 1.4, as approved by Russell Reported by blitzrage Closes issue ASTERISK-10460 ........ ------------------------------------------------------------------------ |