Skip to content

Fix: CONTAINS condition fails to match a value containing a backslash#20

Open
benno-truevault wants to merge 1 commit intomasterfrom
fix/where_contains_backslash
Open

Fix: CONTAINS condition fails to match a value containing a backslash#20
benno-truevault wants to merge 1 commit intomasterfrom
fix/where_contains_backslash

Conversation

@benno-truevault
Copy link
Copy Markdown
Collaborator

E.g.

Pdb::query("
CREATE TABLE IF NOT EXISTS ~dummy(
    id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    value varchar(255) NOT NULL
)", [], 'null');

try {
    Pdb::insert('dummy', ['id' => 1, 'value' => 'a\b']);
} catch (Exception) {
    // Assume record exists
}

function findRecord($conditions)
{
    $res = Pdb::find('dummy', $conditions)->all();
    echo json_encode($conditions, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), ' -> ';
    echo json_encode($res, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
}

findRecord(['value' => 'a\b']); // OK
findRecord([['value', 'CONTAINS', 'a\b']]); // Fails without this fix

Copy link
Copy Markdown
Collaborator

@gwillz gwillz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No-brainer.

@TheJosh
Copy link
Copy Markdown

TheJosh commented Apr 29, 2026

Earlier versions of sprout used str_replace and the replacement order matters in this case; the \ replacement has to be BEFORE the % replacement otherwise it breaks.

I'm not sure the replacement order for strtr but it might be worth investigating or testing this too.

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.

3 participants