From c0639ce6180dca1fb0798c19e8285408dec4552c Mon Sep 17 00:00:00 2001 From: Carsten Rose <carsten.rose@math.uzh.ch> Date: Fri, 29 Apr 2016 15:30:14 +0200 Subject: [PATCH] AbstractBuildForm.php: fixed bug that empty formElement['maxlength'] parameter crashes substr(). --- extension/qfq/qfq/AbstractBuildForm.php | 2 +- .../qfq/tests/phpunit/fixtures/Generic.sql | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php index bb71a4a7f..4ef9cfacb 100644 --- a/extension/qfq/qfq/AbstractBuildForm.php +++ b/extension/qfq/qfq/AbstractBuildForm.php @@ -1676,7 +1676,7 @@ abstract class AbstractBuildForm { } // truncate if necessary - if ($value != '') { + if ($value != '' && $formElement['maxLength'] > 0) { $value = substr($value, 0, $formElement['maxLength']); } diff --git a/extension/qfq/tests/phpunit/fixtures/Generic.sql b/extension/qfq/tests/phpunit/fixtures/Generic.sql index a8d17684f..8e5dafc56 100644 --- a/extension/qfq/tests/phpunit/fixtures/Generic.sql +++ b/extension/qfq/tests/phpunit/fixtures/Generic.sql @@ -16,6 +16,7 @@ DROP TABLE IF EXISTS Note; CREATE TABLE Note ( id BIGINT AUTO_INCREMENT PRIMARY KEY, gr_id INT(11) NOT NULL DEFAULT 0, + person_id BIGINT(20) DEFAULT NULL, value VARCHAR(128), t1 TEXT, t2 TEXT @@ -25,3 +26,20 @@ INSERT INTO Note (gr_id, value, t1, t2) VALUES (1, 'First note - constants', 'Latest Information', 'Dear User\nt\n you\'re invited to to our Christmas party'), (2, 'Second note - some variables', 'Latest Information: {{party:C:all}}', 'Dear {{Firstname:C:all}} {{Lastname:C:all}}\n\n you\'re invited to to our Christmas party'); + + +DROP TABLE IF EXISTS Address; +CREATE TABLE Address ( + id BIGINT(20) NOT NULL AUTO_INCREMENT, + person_id BIGINT(20) NOT NULL DEFAULT 0, + street VARCHAR(128) NOT NULL DEFAULT '', + city VARCHAR(128) NOT NULL DEFAULT '', + country ENUM('', 'Switzerland', 'Austria', 'France', 'Germany') NOT NULL DEFAULT '', + PRIMARY KEY (`id`) +); + +INSERT INTO Address (person_id, street, city) VALUES + (1, 'Side Street', 'Zurich'), + (1, 'Park Street', 'Zurich'), + (1, 'Winter Street', 'Zurich'), + (2, 'Summer Street', 'Zurich'); -- GitLab