diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 60207b1be..319fe85f7 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -1639,7 +1639,7 @@ class G * @param string $sqlString The string to be escaped * @param string $DBEngine Target DBMS */ - public function sqlEscape($sqlString, $DBEngine = DB_ADAPTER) + public static function sqlEscape($sqlString, $DBEngine = DB_ADAPTER) { $DBEngine = DB_ADAPTER; switch ($DBEngine) { @@ -1748,12 +1748,12 @@ class G } //Non-quoted if (($match[1][$r][0] == '#') && (isset($result[$match[2][$r][0]]))) { - $__textoEval .= G::replaceDataField($result[$match[2][$r][0]], $result); + $__textoEval .= $result[$match[2][$r][0]]; continue; } //Non-quoted = if (($match[1][$r][0] == '=') && (isset($result[$match[2][$r][0]]))) { - $__textoEval .= G::replaceDataField($result[$match[2][$r][0]], $result); + $__textoEval .= $result[$match[2][$r][0]]; continue; } //Objects attributes diff --git a/tests/unit/gulliver/system/ReplaceDataFieldTest.php b/tests/unit/gulliver/system/ReplaceDataFieldTest.php new file mode 100644 index 000000000..231859f93 --- /dev/null +++ b/tests/unit/gulliver/system/ReplaceDataFieldTest.php @@ -0,0 +1,96 @@ + + + + + +

THIS IS ONLY A TEST OF THE VARIABLE             @#var_supplierEmail           

+ + '; + + $result = [ + 'var_supplierEmail' => 'asa@qq.fds', + 'var_supplierEmail_label' => 'asa@qq.fds', + ]; + + $dbEngine = 'mysql'; + + // Replace variables in the string + $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + + // Assert the @qq is not being set as an empty value + $this->assertRegExp("/asa@qq.fds/", $stringToCheck); + + // Testing with a "@qstring" value + $result = [ + 'var_supplierEmail' => '@qstring', + 'var_supplierEmail_label' => '@qstring', + ]; + + $dbEngine = 'mysql'; + + // Replace variables in the string + $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + + // Assert the @qstring is not being set as an empty value + $this->assertRegExp("/@qstring/", $stringToCheck); + } + + /** + * Check that the value of "@q" followed by a string is not being set as empty when using "@=" to identify a variable + * + * @test + * @covers G::replaceDataField + */ + public function it_should_not_set_empty_when_calling_a_variable_with_equals_symbol() + { + $string = ' + + + + +

THIS IS ONLY A TEST OF THE VARIABLE             @=var_supplierEmail           

+ + '; + + $result = [ + 'var_supplierEmail' => 'asa@qq.fds', + 'var_supplierEmail_label' => 'asa@qq.fds', + ]; + + $dbEngine = 'mysql'; + + // Replace variables in the string + $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + + // Assert the @qq is not being set as an empty value + $this->assertRegExp("/asa@qq.fds/", $stringToCheck); + + // Testing with a "@qstring" value + $result = [ + 'var_supplierEmail' => '@qstring', + 'var_supplierEmail_label' => '@qstring', + ]; + + $dbEngine = 'mysql'; + + // Replace variables in the string + $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + + // Assert the @qstring is not being set as an empty value + $this->assertRegExp("/@qstring/", $stringToCheck); + } +}