Commit f86bafee authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3425 / Form.parameter, FormElement.parameter: comment handling, trailing & leading spaces

Manual.rst: commented handling of 'comment character' and 'escaping of leading/trailing spaces'
Support.php: new funtion handleEscapeSpaceComment().
Evaluate.php: parse all F|FE.parameter via handleEscapeSpaceComment().
parent c075fc24
......@@ -470,8 +470,6 @@ Sanitize class
| **all** | Form | Query | no sanitizing |
+------------------+------+-------+-----------------------------------------------------------------------------------------+
Store
=====
......@@ -1005,8 +1003,6 @@ parameter
* The following parameter are optional and can be configured in the *Form.parameter* field.
* Comments: lines starting with a '#' are treated as a comment and will not be parsed.
+--------------------------+--------+----------------------------------------------------------------------------------------------------------+
| Name | Type | Description |
+==========================+========+==========================================================================================================+
......@@ -1065,6 +1061,18 @@ parameter
* class = container-fluid
* classBody = qfq-form-right
.. _comment-space-character:
Comment- and space-character
''''''''''''''''''''''''''''
* Lines will be trimmed - leading and trailing spaces will be removed.
* If a leading and/or trailing space is needed, escape it: '\ hello world \' > ' hello world '.
* Lines starting with a '#' are treated as a comment and will not be parsed. Suche lines are treated as 'empty lines'
* The comment sign can be escaped with '\'
submitButtonText
''''''''''''''''
......@@ -1147,7 +1155,7 @@ FormElements
* Additional options to a *FormElement* will be configured via the *FormElement.parameter* field (analog to *Form.parameter*
for *Forms* ).
* Comments: lines starting with a '#' are treated as a comment and will not be parsed.
* See also: :ref:`comment-space-character`
.. _class-container:
......
......@@ -68,12 +68,9 @@ class Evaluate {
if (is_array($value)) {
$arr[] = $this->parseArray($value, $skip);
} else {
$value = trim($value);
$value = Support::handleEscapeSpaceComment($value);
// Skip comments.
if (substr($value, 0, 1) != '#') {
$arr[$key] = $this->parse($value, 0, $debugStack);
}
$arr[$key] = $this->parse($value, 0, $debugStack);
}
}
......
......@@ -704,6 +704,39 @@ class Support {
return ($val == '' || $val == false) ? '0' : $val;
}
/**
* Check if the string starts with the comment sign - return an empty string.
* Check if the string starts with an escaped comment sign - strip the escape character.
* Check if the string starts or ends with an 'escape space' - strip the escape character.
*
* @param string $str
* @return string
*/
public static function handleEscapeSpaceComment($str) {
$str = trim($str);
// Skip comments.
if (substr($str, 0, 1) == '#') {
$str = ''; // It's necessary to create an empty entry - E.g. Form.title will not exist if is a comment, but later processing expects that there is an string.
} else {
switch (substr($str, 0, 2)) {
case '\#':
case '\ ':
$str = substr($str, 1);
break;
default:
break;
}
if (substr($str, -1) == '\\') {
$str = substr($str, 0, strlen($str) - 1);
}
}
return $str;
}
/**
* TODO: as soon as we don't support PHP 5.6.0 anymore, this local implemention can be removed.
* Workaround for PHP < 5.6.0: there is no ldap_escape() - use this code instead.
......@@ -779,4 +812,5 @@ class Support {
}
}
}
\ No newline at end of file
......@@ -359,7 +359,6 @@ class EvaluateTest extends \AbstractDatabaseTest {
}
protected function setUp() {
$this->store = Store::getInstance('form=TestFormName', true);
......
......@@ -422,6 +422,24 @@ class SupportTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals('<div class="qfq" class="123">', $new);
}
public function testunEscapeNComment() {
$this->assertEquals('', Support::handleEscapeSpaceComment(''));
$this->assertEquals('', Support::handleEscapeSpaceComment(' '));
$this->assertEquals('Hello world.', Support::handleEscapeSpaceComment('Hello world.'));
$this->assertEquals('Hello world.', Support::handleEscapeSpaceComment(' Hello world. '));
$this->assertEquals('', Support::handleEscapeSpaceComment('#Hello world.'));
$this->assertEquals('', Support::handleEscapeSpaceComment(' #Hello world. '));
$this->assertEquals('', Support::handleEscapeSpaceComment(' # Hello world. '));
$this->assertEquals('# Hello world.', Support::handleEscapeSpaceComment('\# Hello world. '));
$this->assertEquals('Hello world. ', Support::handleEscapeSpaceComment('Hello world. \\'));
$this->assertEquals('Hello world. ', Support::handleEscapeSpaceComment('Hello world. \ '));
$this->assertEquals(' Hello world.', Support::handleEscapeSpaceComment('\ Hello world.'));
$this->assertEquals(' Hello world. ', Support::handleEscapeSpaceComment('\ Hello world. \ '));
}
/**
* @expectedException \qfq\CodeException
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment