From d075fa56a2a26ce104db43a466caee6bc451b70f Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 4 Aug 2022 20:29:02 +0100 Subject: [PATCH 1/2] A table may be named "0" Signed-off-by: Kamil Tekiela --- libraries/classes/Sql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php index 098eef87d2..2053d2dbcc 100644 --- a/libraries/classes/Sql.php +++ b/libraries/classes/Sql.php @@ -1448,7 +1448,7 @@ class Sql } } - $hasUnique = $table && $this->resultSetContainsUniqueKey($db, $table, $fieldsMeta); + $hasUnique = $table !== null && $this->resultSetContainsUniqueKey($db, $table, $fieldsMeta); $editable = ($hasUnique || $GLOBALS['cfg']['RowActionLinksWithoutUnique'] From 06d58c96622389d86a74e23bd709706857cbc11a Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 4 Aug 2022 20:59:31 +0100 Subject: [PATCH 2/2] Fix bug #17663 Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 5 +- test/classes/InsertEditTest.php | 120 +++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 3 deletions(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 7ea09e576f..33b692777d 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1674,9 +1674,8 @@ class InsertEdit } elseif ( ! (empty($multiEditFuncs[$key]) && isset($multiEditColumnsPrev[$key]) - && (($currentValue === "'" . $this->dbi->escapeString($multiEditColumnsPrev[$key]) . "'") - || ($currentValue === '0x' . $multiEditColumnsPrev[$key]))) - && $currentValue + && $currentValue === $multiEditColumnsPrev[$key]) + && $currentValueAsAnArray !== '' ) { // avoid setting a field to NULL when it's already NULL // (field had the null checkbox before the update diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 1c7ad8eee3..13ee204b74 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -2023,6 +2023,126 @@ class InsertEditTest extends AbstractTestCase ], $result ); + + // Test to see if a zero-string is not ignored + $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit( + $multi_edit_columns_name, + [], + '0', + [], + [], + false, + [], + [], + "'0'", + [], + '0', + [] + ); + + $this->assertEquals( + [ + ["`fld` = '0'"], + [], + ], + $result + ); + + // Can only happen when table contains blob field that was left unchanged during edit + $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit( + $multi_edit_columns_name, + [], + '', + [], + [], + false, + [], + [], + '', + [], + '0', + [] + ); + + $this->assertEquals( + [ + [], + [], + ], + $result + ); + + // Test to see if a field will be set to null when it wasn't null previously + $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit( + $multi_edit_columns_name, + ['on'], + '', + [], + [], + false, + [], + [], + 'NULL', + [], + '0', + [] + ); + + $this->assertEquals( + [ + ['`fld` = NULL'], + [], + ], + $result + ); + + // Test to see if a field will be ignored if it was null previously + $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit( + $multi_edit_columns_name, + ['on'], + '', + [], + [], + false, + [], + [], + 'NULL', + [], + '0', + ['on'] + ); + + $this->assertEquals( + [ + [], + [], + ], + $result + ); + + // Test to see if a field will be ignored if it the value is unchanged + $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit( + $multi_edit_columns_name, + [], + "a'b", + ["a'b"], + [], + false, + [], + [], + "'a\'b'", + [], + '0', + [] + ); + + $this->assertEquals( + [ + [], + [], + ], + $result + ); } /**