From: <de...@de...> - 2007-04-04 08:25:23
|
Author: CrawfordCurrie Date: 2007-04-04 03:25:22 -0500 (Wed, 04 Apr 2007) New Revision: 13264 Modified: twiki/branches/MAIN/lib/TWiki/Func.pm twiki/branches/MAIN/test/unit/FuncTests.pm Log: Item3841: added expandStandardEscapes to the functionality exported in Func. Modified: twiki/branches/MAIN/lib/TWiki/Func.pm =================================================================== --- twiki/branches/MAIN/lib/TWiki/Func.pm 2007-04-04 01:05:43 UTC (rev 13263) +++ twiki/branches/MAIN/lib/TWiki/Func.pm 2007-04-04 08:25:22 UTC (rev 13264) @@ -2235,7 +2235,7 @@ =http://server:port/bin/rest/EmptyPlugin/restExample= (ie, with the name of the function instead of the alias) will not work. - + =cut sub registerRESTHandler { @@ -2260,6 +2260,41 @@ =pod +---++ expandStandardEscapes($str) -> $unescapedStr + +TWiki has an informal standard set of escapes used in =format= +parameters used to block evaluation of paramater strings. For example, if +you were to write + +=%<nop>MYTAG{format="%<nop>WURBLE%"}%= + +then %<nop>WURBLE would be expanded *before* %<NOP>MYTAG is evaluated. To avoid +this TWiki uses escapes in the format string. For example: + +=%<nop>MYTAG{format="$percntWURBLE$percnt"}%= + +This lets you enter arbitrary strings into parameters without worrying that +TWiki will expand them before your plugin gets a chance to deal with them +properly. Once you have processed your tag, you will want to expand these +escapes to their proper value. That's what this function does. + +| *Escape:* | *Expands To:* | +| =$n= or =$n()= | New line. Use =$n()= if followed by alphanumeric character, e.g. write =Foo$n()Bar= instead of =Foo$nBar= | +| =$nop= or =$nop()= | Is a "no operation". | +| =$quot= | Double quote (="=) | +| =$percnt= | Percent sign (=%=) | +| =$dollar= | Dollar sign (=$=) | + +*Since:* TWiki::Plugins::VERSION 1.12 + +=cut + +sub expandStandardEscapes { + return TWiki::expandStandardEscapes( @_ ); +} + +=pod + ---++ Searching =cut Modified: twiki/branches/MAIN/test/unit/FuncTests.pm =================================================================== --- twiki/branches/MAIN/test/unit/FuncTests.pm 2007-04-04 01:05:43 UTC (rev 13263) +++ twiki/branches/MAIN/test/unit/FuncTests.pm 2007-04-04 08:25:22 UTC (rev 13264) @@ -552,5 +552,28 @@ } +sub test_expandStandardEscapes { + my $this = shift; + + my $input = <<'TEST'; +$n embed$nembed$n()embed +$nop embed$nopembed$nop()embed +$quot embed$quotembed$quot()embed +$percnt embed$percntembed$percnt()embed +$dollar embed$dollarembed$dollar()embed +TEST + my $expected = <<'TEST'; + + embed$nembed +embed + embedembedembed +" embed"embed"embed +% embed%embed%embed +$ embed$embed$embed +TEST + my $output = TWiki::Func::expandStandardEscapes($input); + $this->assert_str_equals($expected, $output); +} + 1; |