Skip to content

#461 broke the like operator when special characters are used ,:() #477

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

Closed
Sandr0x00 opened this issue Jul 23, 2024 · 2 comments · Fixed by #481
Closed

#461 broke the like operator when special characters are used ,:() #477

Sandr0x00 opened this issue Jul 23, 2024 · 2 comments · Fixed by #481
Assignees
Labels
bug Something isn't working

Comments

@Sandr0x00
Copy link

Bug report

Describe the bug

Before the change in #461, the "like" query was built like this with :value%

like.%3Avalue%25

Since the change, it is built like this:

like.%22%3Avalue%2A%22

The reason is the called pattern = sanitize_pattern_param(pattern) which surrounds the value with " whenever a "special" character ,:() is in the request.

Using " around the value will result in an empty set to be returned instead of the actual data matching :value%.

To Reproduce

Do a select query with

.like("column", ":value%")

and check the result returned from the database.

Expected behavior

Using the like operator and get values in return

@Sandr0x00 Sandr0x00 added the bug Something isn't working label Jul 23, 2024
@silentworks
Copy link
Contributor

Please provide concrete examples when you are supplying steps to reproduce an issue. column and value aren't concrete examples, they are very abstract.

@Sandr0x00
Copy link
Author

Sandr0x00 commented Jul 24, 2024

Well, the bug is universal and triggers in any case explained, but sure. Create a table like

CREATE TABLE tbl
(
    id int PRIMARY KEY generated always as identity,
    col text
);

INSERT INTO tbl
    (col)
VALUES
    ('http://web.site'),
    ('https://web.page'),
    ('http://google.com'),
    ('https://github.com');

and execute the following script (I use the supabase since it's a convenient, but it's just a wrapper around postgrest, and the issue is in the like function).

import logging
import os
from supabase import create_client
from postgrest import SyncRequestBuilder

# logging to see the httpx request created
logging.basicConfig(
    level=logging.INFO
)

# supabase wrapper
client = create_client(
    os.getenv("SUPABASE_URL"),
    os.getenv("SUPABASE_SERVICE_ROLE_KEY")
)
req_builder: SyncRequestBuilder = client.table("tbl")

# from here on, only postgrest functions
data = req_builder.select("*").like("col", "https://%").execute().data
print(data)

Before the changes in #461, it was working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants