Skip to content

Conversation

@HLeithner
Copy link
Contributor

Pull Request for Issue #327

@richard67
Copy link
Contributor

richard67 commented Mar 22, 2025

The change of the quoteNameStr seems not to be fully b/c as there is a change in behaviour when the string to be quoted contains a dot and another difference when an array element is null.

When you call the old, unmodified, deprecated method with the following array as argument

['foo.bar','foo`bar','foo"bar','foo[bar','foo]bar',null]

you get with MySQL names quotes:

`foo.bar`.`foo`bar`.`foo"bar`.`foo[bar`.`foo]bar`

With this PR you get:

`foo`.`bar`.`foo``bar`.`foo"bar`.`foo[bar`.`foo]bar`.``

The same applies with other names quotes (PostgreSQL, MS SQL Server).

The first array element with the dot is quoted differently.

The second array element shows the fix for the issue.

The last array element shows the difference when null.

If that b/c break is a problem, I suggest following different implementation:

    function quoteNameStr($strArr)
    {
        $parts = [];

        foreach ($strArr as $part) {
            if ($part === null) {
                continue;
            }

            $parts[] = quoteNameString($part, true);
        }

        return implode('.', $parts);
    }

Mind the 2nd parameter of the quoteNameString call.

My suggested code gives following result for the example array:

`foo.bar`.`foo``bar`.`foo"bar`.`foo[bar`.`foo]bar`

The same applies when using PostgreSQL or MS SQL Server names quotes: With both ways the issue would be fixed, but with this PR the first array element with the dot is quoted differently.

You can test that here: https://onlinephp.io/c/26575

Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
@HLeithner
Copy link
Contributor Author

thanks richard

@richard67
Copy link
Contributor

@SniperSister @ramalama Could you check this PR again? Thanks in advance.

@richard67 richard67 changed the title Replace incorrect working quoteNameStr method [2.x] Replace incorrect working quoteNameStr method Mar 23, 2025
@Hackwar Hackwar merged commit 1a45905 into 2.0-dev Mar 30, 2025
2 of 4 checks passed
@Hackwar Hackwar deleted the 2.0/replace-quotenamestr branch March 30, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants