Quoting of Action parameters


Currently (version 1.1.6.0 and earlier), Wikka recognizes only action parameters if they are enclosed in single quotes. That is a needless limitation, and unintuitive for those who are used to be able to single-quote attributes in HTML.

Double or Single Quotes

This page shows a small change to the Action() method in wikka.php than enables it to recognize parameters enclosed in either double or single quotes (as long as the same type quotation character is used at start and end of the value).

Making the change


Find the Action() method in wikka.php (line 759 in version 1.1.6.0). A few lines into the method, find this section of code:
  1.             if ($action) {
  2.                 // match all attributes (key and value)
  3.                 preg_match_all("/([A-Za-z0-9]*)=\"(.*)\"/U", $vars_temp, $matches);
  4.  
  5.                 // prepare an array for extract() to work with (in $this->IncludeBuffered())
  6.                     if (is_array($matches)) {
  7.                         for ($a = 0; $a < count($matches[0]); $a++) {
  8.                             $vars[$matches[1][$a]] = $matches[2][$a];
  9.                         }
  10.                     }
  11.                 $vars["wikka_vars"] = trim($vars_temp); // <<< add the buffered parameter-string to the array
  12.             } else {


Replace it with:
  1.             if ($action) {
  2.                 // match all attributes (key and value)
  3.                 preg_match_all('/([A-Za-z0-9]*)=("|\')(.*)\\2/U', $vars_temp, $matches);
  4.  
  5.                 // prepare an array for extract() to work with (in $this->IncludeBuffered())
  6.                 if (is_array($matches)) {
  7.                     for ($a = 0; $a < count($matches[0]); $a++) {
  8.                         $vars[$matches[1][$a]] = $matches[3][$a];
  9.                     }
  10.                 }
  11.                 $vars['wikka_vars'] = trim($vars_temp); // <<< add the buffered parameter-string to the array
  12.             } else {


How it works


In the original regular expression on line 774
"/([A-Za-z0-9]*)=\"(.*)\"/U"
the bit
=\"(.*)\"
matches an attribute value as follows:

In the new code we have this regular expression
'/([A-Za-z0-9]*)=("|\')(.*)\\2/U'
where the bit
=("|\')(.*)\\2
matches an attribute value as follows:

Advantages


  1. Freedom to use either single or double quotes around a parameter value; it's largely a matter of habit, but in some cases single quotes may actually be more readable than double quotes.
  1. You can now embed quotes in a parameter value, simply by enclosing the whole parameter in the "opposite" type of quote characters. This is useful for passing actual text to an action, but would also enable something like the (extended) TableAction to handle embedded (double-double quoted) HTML in table cells.


CategoryDevelopmentCore
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki