<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
    <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://reviewboard.asterisk.org/r/3616/">https://reviewboard.asterisk.org/r/3616/</a>
     </td>
    </tr>
   </table>
   <br />



 <p>Ship it!</p>



 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Please commit against 1.8+.  r3619 passes against 1.8 with this change, fails without it.</pre>
 <br />









<p>- Corey Farrell</p>


<br />
<p>On June 12th, 2014, 6:53 p.m. EDT, Mark Michelson wrote:</p>








<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/static/rb/images/review_request_box_top_bg.ab6f3b1072c9.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
 <tr>
  <td>

<div>Review request for Asterisk Developers.</div>
<div>By Mark Michelson.</div>


<p style="color: grey;"><i>Updated June 12, 2014, 6:53 p.m.</i></p>









<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt;">Repository: </b>
Asterisk
</div>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
 <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Asterisk has an interesting asymmetry when it comes to reading and writing channel variables. When setting a channel variable, you can do something like:

exten => foo,n,Set(__BAR=hello)

But when you read from that variable, you will not get the same result by doing

exten => foo,n,NoOp(${__BAR})

That will evaluate to an empty string. Instead, you must reference the variable without the leading underscores:

exten => foo,n,NoOp(${BAR})

That will evaluate to "hello"

This asymmetry mostly does not cause problems, except in rare cases, like the PUSH and UNSHIFT dialplan functions. Take the following sample dialplan:

exten => foo,1,Set(PUSH(__BAR)=hello)
exten => foo,2,NoOp(${BAR})
exten => foo,3,Set(PUSH(__BAR)=world)
exten => foo,4,NoOp(${BAR})

In this case, you want to have an inheritable array and be able to push values onto the back of it. The above construct, though, does not do what is expected. At priority 2, BAR evaluates to "hello" as you might expect. However, at priority 4, BAR evaluates to "world" instead of the expected "hello,world".

The problem here is that the PUSH and UNSHIFT dialplan functions work in both a read and write context for a channel variable. They first read the variable in order to get the previously set value, and they then write the new value to the beginning or end of the array. Because of the earlier example I gave where trying to evaluate ${__BAR} did not give the previously-set value, attempting to PUSH or UNSHIFT with a __ variable did not have the expected result.

This patch aims to fix the problem by retrieving the variable without the leading underscores but then setting the new value with leading underscores.

There are other dialplan functions in func_strings that take variable names as parameters (FIELDQTY, FIELDNUM, LISTFILTER, REPLACE, STRREPLACE, EVAL, SHIFT, and POP), but these all are intended to evaluate or modify pre-existing channel variables rather than to (possibly) create variables. For that reason, none of the other dialplan functions in func_strings.c are touched by this patch.</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">The sample dialplan in the description evaluates to "hello,world" at priority 4 with this patch applied.

I am working on an official testsuite test, but I am currently having difficulties with the testsuite.</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>/branches/12/funcs/func_strings.c <span style="color: grey">(416051)</span></li>

</ul>

<p><a href="https://reviewboard.asterisk.org/r/3616/diff/" style="margin-left: 3em;">View Diff</a></p>







  </td>
 </tr>
</table>








  </div>
 </body>
</html>