[pmwiki-users] Hg pattern error

Patrick R. Michaud pmichaud at pobox.com
Thu Apr 26 08:29:21 CDT 2007


On Thu, Apr 26, 2007 at 04:50:54AM -0400, The Editor wrote:
> On 4/25/07, the Other michael <xraysmalevich at gmail.com> wrote:
> > I've tried installing Hierarchical groups
> > (http://www.pmwiki.org/wiki/Cookbook/Hg), but a pattern error(?)
> > appears at the bottom of every page in the navigation:
> >
> > <div id='footnav' class='navbuttons'>pat=/\[\[([\-|\*|\^]+)(.*?)\]\]/e

The 'pat=/.../' is an error message reported back indicating
that an error occurred while processing the markup rule.
Because the error occurs inside the preg_replace() function,
PmWiki (and PHP) can't really provide much more details about
the error than the fact that one occurred.  

IIRC, the message can occur if there's an error in the
function called by the replace string when /e is present.

> Very strange.  I'm presuming when you turn off Hg it disappears?  
> Hg does use:
> 
> Markup('[[hg','<var','/\\[\\[([\\-|\\*|\\^]+)(.*?)\\]\\]/e',
> 'hgLinks1("$1","$2")');

That pattern looks very odd to me.  As written it is saying
to match '[[', followed by one or more of '-', '|', '*', '|',
or '^', followed by anything else up to a closing ']]' .  
At the very least, the '|' doesn't need to appear twice;
but I suspect that the pattern wasn't intended to be matching
'|' at all.

Also, the '<var' specification is probably wrong, since PmWiki
doesn't come with a 'var' rule.  I suspect '<{$var}' is
intended here.  (I would've probably written this rule to
occur much later, however -- something more like '<links'
to have it done just before links get processed, instead of
extremely early in the sequence as happens here.)

Lastly, it's somewhat dangerous to write the replace portion as 
'hgLinks1("$1", "$2")' :

- Because $2 is inside of double quotes (i.e., "$2") when
  the replacement pattern is evaluated, anything that looks like
  a variable or backslash escape sequence will be interpolated
  instead of taken literally.  This could result in an interpolation
  error, which would explain the pat= messages, but it also
  has the potential to allow authors to view the contents of
  other PHP global variables.

- PHP will automatically add backslashes in front of any
  quotation marks that occur in $2, which will be different
  from what the author intended.

Whenever a PmWiki markup rule uses /e, I *always* specify the
replacement rule using double quotes, and use PSS(...) around 
any $1, $2, etc. arguments that might contain quotes or 
backslashes.  I would write the replacement parameter as

  "hgLinks1('$1', PSS('$2'))"

Fixing the above may not resolve the pat= problem, but it
would be a start.

> Also you might try the Cluster recipe and see if it does the same
> thing--though it uses the same pattern exactly.

Cluster (2007-03-25) uses

  Markup('[[cluster','<var','/\\[\\[(-|[\\*\\^]+)(.*?)\\]\\]/e', 
    'ClusterLinks($pagename, "$1", "$2")');

The match pattern makes *much* more sense to me here, although
the markup rule still has the issues with the '<var' 
specification and the use of "$2" in the replacement pattern.

Hope this helps,

Pm



More information about the pmwiki-users mailing list