Difference between revisions of "Issue:Includematch parameter regexp issue"

From FollowTheScore
Jump to: navigation, search
(New page: {{Issue |Type = Bug |Extension = DPL |Version = 1.4.7 |Description = includematch parameter does not work with complex regexp |Status = open }} == Problem == I have...)
 
Line 4: Line 4:
 
  |Version    = 1.4.7
 
  |Version    = 1.4.7
 
  |Description = includematch parameter does not work with complex regexp
 
  |Description = includematch parameter does not work with complex regexp
  |Status      = open
+
  |Status      = answered
 
}}
 
}}
  
Line 66: Line 66:
  
 
== Reply ==
 
== Reply ==
 +
The <tt>includematch</tt> parameter uses the comma as a separator. Each comma delimited token is matched against its corresponding parameter from the <tt>include</tt> statement. The first comma in your argument is taken as a separator and then DPL complains about a missing trailing  "/" in "/project\s*=\s*([^" which is quite reasonable, isn´t it?
 +
 +
Try to escape the comma by using &#number syntax.
 +
 +
[[User:Gero|Gero]] 18:32, 12 October 2007 (CEST)

Revision as of 17:32, 12 October 2007

Description: includematch parameter does not work with complex regexp
Extension / Version: DPL   /   1.4.7
Type / Status: Bug   /   answered

Problem

I have the following templates: Template:Todo with the following code

Do task for project {{{project}}}

where the project= option is a comma separated list of projects to which this particular TODO is associated with (see below for valid variations of project option). I also have the following template Template:Todo.dpl with the following code

<includeonly>
* {{{1}}}
</includeonly>


I want to write a DPL query to display only the tasks assigned to a particular project (let's call it myproj). I tried doing the following

<dpl>
  uses=Template:Todo
  include={Todo}.dpl
  includematch=/project\s*=\s*([^,]*,)*\s*myproj\s*(,[^,]*\s*)*$/i
</dpl>

However, when I view a page with this DPL code, I get a LOT of error messages similar to Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in /export/www/html/npdwiki/extensions/DynamicPageList/DynamicPageList2Include.php on line 429 and the results are not correct: the query does not display any matches.

The following PHP code demonstrates the application of this template to match against several valid and invalid options for project= parameter.

<?php

$test = array();
array_push($test, "project=myproj");
array_push($test, "project = myproj");
array_push($test, "project = blah,  myproj");
array_push($test, "project=blah ,   myproj");
array_push($test, "project = blah blah blah , myproj ");
array_push($test, "project = myproj, blah blah");
array_push($test, "project = blah , myproj , blah");
array_push($test, "project = myproj two");
array_push($test, "project = blah, myproj two, blha");
array_push($test, "project = myproj ,myproj two");
array_push($test, "project = myproj two , myproj");

foreach ($test as $t) {
    print "testing '$t' ==> ";
    if (preg_match('/project\s*=\s*([^,]*,)*\s*myproj\s*(,[^,]*\s*)*$/i', $t))
        print "match \n";
    else
        print "NOT matching\n";
}

?>
--Gri6507 16:05, 12 October 2007 (CEST)


Reply

The includematch parameter uses the comma as a separator. Each comma delimited token is matched against its corresponding parameter from the include statement. The first comma in your argument is taken as a separator and then DPL complains about a missing trailing "/" in "/project\s*=\s*([^" which is quite reasonable, isn´t it?

Try to escape the comma by using &#number syntax.

Gero 18:32, 12 October 2007 (CEST)