Escaping a greater than symbol in the string tool

Eric Samson's Avatar

Eric Samson

27 Apr, 2012 08:45 PM

Velocity doesn't seem to like the > character when testing in the string tool:

#set($echoVal = '"Output Text"')
#set($testPhpText = "<?php echo $echoVal; ?><p>Some HTML.</p><?php morePhp(); ?>")
#set($afterPhp = $_StringTool.substringAfter($testPhpText, "?>"))

output = | $afterPhp |

This give an empty string as a result because there is something happening with the greater than symbol. If I just use a ? it works, or if I test for the whole value of '"<?php echo $echoVal; ?>' as the test it works, but just '?>' makes it fail. Any ideas?

  1. 2 Posted by Eric L. Epps on 06 Jun, 2012 08:41 PM

    Eric L. Epps's Avatar

    I don't think your issue is a result of escaping. Looks like it's returning an empty string because there is no string after the second ?>.

    Compare the results of this with your results:

    #set($echoVal = '"Output Text"')
    #set($testPhpText = "<?php echo $echoVal; ?><p>Some HTML.</p><?php morePhp(); ?><p>Still more HTML</p>")
    #set($afterPhp = $_StringTool.substringAfter($testPhpText, "?>"))
    
    output = | $afterPhp |
    
  2. Support Staff 3 Posted by Ryan Griffith on 25 Jun, 2012 06:08 PM

    Ryan Griffith's Avatar

    Hi Eric,

    I was going over some older discussions and noticed this one is still open. Were you able to get your Velocity format working?

    Please feel free to let us know if you have any other questions.

    Thanks.

  3. 4 Posted by James White on 26 Jun, 2012 11:56 AM

    James White's Avatar

    All Eric number 2 does is give an example of a text string on which $_StringTool.substringAfter does HAPPEN to work, he gives no mechanism for making the correct answer appear on Eric number 1's text. You can easily see that with the following which uses both of their strings and a "sample" string without a ">" (though it may be the "?>" pair that is the issue, I don't know for sure).

    #macro(myTextareaOut $inOrig $inResult)
    #set($outResult = "Original: $inOrig
    Result: $inResult")
    #set($outResult = $outResult.replace('<', '&lt;'))
    #set($outResult = $outResult.replace('>', '&gt;'))
    <form><textarea cols="140" rows="10">
    $outResult
    </textarea></form>
    #end###myTextareaOut
    #set($testPhpText = "Ordinary ?? multiple target ?? string")
    #set($afterPhp = $_StringTool.substringAfter($testPhpText, "??"))
    #myTextareaOut($testPhpText $afterPhp)
    #set($testPhpText = "<?php echo $echoVal; ?><p>Some HTML.</p><?php morePhp(); ?>")
    #set($afterPhp = $_StringTool.substringAfter($testPhpText, "?>"))
    #myTextareaOut($testPhpText $afterPhp)
    #set($testPhpText = "<?php echo $echoVal; ?><p>Some HTML.</p><?php morePhp(); ?><p>Still more HTML</p>")
    #set($afterPhp = $_StringTool.substringAfter($testPhpText, "?>"))
    #myTextareaOut($testPhpText $afterPhp)
    
  4. 5 Posted by James White on 26 Jun, 2012 01:46 PM

    James White's Avatar

    Hey moderator, I guess cut and paste doesn't correctly represent what is entered. This one will do the code as a file.

    All Eric number 2 does is give an example of a text string on which $_StringTool.substringAfter does HAPPEN to work, he gives no mechanism for making the correct answer appear on Eric number 1's text. You can easily see that with the following which uses both of their strings and a "sample" string without a ">" (though it may be the "?>" pair that is the issue, I don't know for sure).

  5. Support Staff 6 Posted by Ryan Griffith on 26 Jun, 2012 04:06 PM

    Ryan Griffith's Avatar

    Hi James,

    Thank you for the heads up, I updated your original post to surround your code in a code block. For future code snippets, feel free to surround your code with @@@ (before and after) to avoid any formatting complications.

  6. Ryan Griffith closed this discussion on 17 Jul, 2012 06:50 PM.

Comments are currently closed for this discussion. You can start a new one.