Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix handling of NULLs when replacing query params #169

Merged
merged 1 commit into from

3 participants

Dmytro Chekaliuk Christophe Coevoet Markus Bachmann
Dmytro Chekaliuk

No description provided.

Twig/DoctrineExtension.php
@@ -269,6 +269,10 @@ static public function escapeFunction($parameter)
case is_object($result) :
$result = addslashes((string) $result);
break;
+
+ case is_null($result) :
Christophe Coevoet Collaborator
stof added a note

Please use `null === $result to be consistent with our coding standards

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Markus Bachmann Baachi commented on the diff
Twig/DoctrineExtension.php
@@ -290,11 +294,11 @@ public function replaceQueryParameters($query, $parameters)
'/\?|(:[a-z0-9_]+)/i',
function ($matches) use ($parameters, &$i) {
$key = substr($matches[0], 1);
- if (!isset($parameters[$i]) && !isset($parameters[$key])) {
+ if (!array_key_exists($i, $parameters) && !array_key_exists($key, $parameters)) {
Markus Bachmann
Baachi added a note

Is this change really necessary?

Try something like replaceQueryParameters('?, ?', array(1, null)) or replaceQueryParameters('?, ?', array(null, 1)) and you'll see :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Christophe Coevoet stof merged commit f61a9b2 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2013
  1. Dmytro Chekaliuk
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +6 −2 Twig/DoctrineExtension.php
8 Twig/DoctrineExtension.php
View
@@ -269,6 +269,10 @@ static public function escapeFunction($parameter)
case is_object($result) :
$result = addslashes((string) $result);
break;
+
+ case null === $result :
+ $result = 'NULL';
+ break;
}
return $result;
@@ -290,11 +294,11 @@ public function replaceQueryParameters($query, $parameters)
'/\?|(:[a-z0-9_]+)/i',
function ($matches) use ($parameters, &$i) {
$key = substr($matches[0], 1);
- if (!isset($parameters[$i]) && !isset($parameters[$key])) {
+ if (!array_key_exists($i, $parameters) && !array_key_exists($key, $parameters)) {
Markus Bachmann
Baachi added a note

Is this change really necessary?

Try something like replaceQueryParameters('?, ?', array(1, null)) or replaceQueryParameters('?, ?', array(null, 1)) and you'll see :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
return $matches[0];
}
- $value = isset($parameters[$i]) ? $parameters[$i] : $parameters[$key];
+ $value = array_key_exists($i, $parameters) ? $parameters[$i] : $parameters[$key];
$result = DoctrineExtension::escapeFunction($value);
$i++;
Something went wrong with that request. Please try again.