[pmwiki-devel] strange conversions: a FmtPageName bug

Hans design5 at softflow.co.uk
Sat Mar 8 17:58:35 CST 2008


I am trying to load an edit form with

  $HandleEditFmt = array(&$PageStartFmt, &$PageEditFmt, &$PageEndFmt);
  PrintFmt($pagename, $HandleEditFmt);

$PageEditFmt gets retrieved from an EditForm page.

But when I use {$$text}as an input control value, it gets converted to
{$readext}. It seems that '$t' gets converted to 'read'.
Other replacement variables avoiding the '$t' don't cause a problem.

After digging into this problem i come up with this discovery:

The problem is caused by short Globals and how they get replaced by
their value in function FmtPageName.
there are a number of short Globals around, some just one letter, and
each can cause the conversion problem:

$c $f $k $m  $o $p $q $t $v $x are some one letter Global var I observe.

I tested this with this markup definition:

Markup('fmttest','directives',
  '/\\(:fmttest\\s(.*?):\\)/ei',
  " FmtPageName( PSS('$1'), \$pagename)");

and this in a page:

(:fmttest a=$a b=$b c=$c d=$d e=$e f=$f g=$g h=$h i=$i j=$j k=$k l=$l m=$m n=$n o=$o p=$p q=$q r=$r s=$s t=$t u=$u v=$v w=$w x=$x y=$y z=$z :)

watch the replacements taking place!

Now the bug is I believe in function FmtPageName line

  $fmt = str_replace(array_keys($g),array_values($g),$fmt);

It replaces strings too aggressively, i.e replaces in a fmt string '$text'
the $t with the value of the Global $t, which is 'read' in my
original problem case.

A less aggressive and more precise replacement can be done instead
with:

  foreach($g as $k=>$v)
        $fmt = preg_replace("/$k/",$v $fmt);

which will not treat the $t in $text as a Global.

I don't know if this a good solution, but I think I made clear what
the problem is.

~Hans




More information about the pmwiki-devel mailing list