Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: prevent bound parameters being [null] when no parameters are given to Predicate#expression() #264

Commits on Dec 5, 2022

  1. Fix: prevent bound parameters being [null] when no parameters are g…

    …iven to `Predicate#expression()`
    
    Around `laminas/laminas-db:2.10.1`, a regression was introduced, in which calling
    `Laminas\Db\Sql\Predicate#expression("an_expression()")` led to crashes like following
    in downstream consumers:
    
    ```
    Laminas\Db\Sql\Exception\RuntimeException: The number of replacements in the expression does not match the number of parameters
    
    vendor/laminas/laminas-db/src/Sql/Expression.php:151
    vendor/laminas/laminas-db/src/Sql/Predicate/PredicateSet.php:178
    vendor/laminas/laminas-db/src/Sql/Predicate/PredicateSet.php:178
    vendor/laminas/laminas-db/src/Sql/Predicate/PredicateSet.php:178
    vendor/laminas/laminas-db/src/Sql/AbstractSql.php:129
    vendor/laminas/laminas-db/src/Sql/Select.php:633
    ```
    
    This was because predicates were initialized with an `array{null}` by
    default, when expressions like `$sql->where->expression("some_expression()")`
    were used.
    
    The usage of `$sql->where->expression("some_expression()", "foo")` remains
    unchanged with this patch.
    
    This fix targets `2.15.x`, and attempts to make predicates safe to use when no
    parameters have been given.
    
    While an existing test has indeed been changed, this shouldn't have any effect for
    downstream consumers, since `Predicate#expression(string)` didn't work (so far)
    anyway, due to the kind of crash highlighted above.
    Ocramius committed Dec 5, 2022
    Configuration menu
    Copy the full SHA
    1c5ad3a View commit details
    Browse the repository at this point in the history