Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix handling of NULLs when replacing query params #169

Merged
merged 1 commit into from

3 participants

@lazyhammer

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) :
@stof 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
@Baachi 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)) {
@Baachi
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
@stof stof merged commit f61a9b2 into doctrine:master

1 check failed

Details default The Travis build could not complete due to an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2013
  1. @lazyhammer
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +6 −2 Twig/DoctrineExtension.php
View
8 Twig/DoctrineExtension.php
@@ -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)) {
@Baachi
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.