api/v0: make escaped sequences work for search

Reorder the regex chars and remove a needless escape while there.
This commit is contained in:
Lucas Gabriel Vuotto 2025-04-28 21:00:32 +00:00
parent 202c6fa878
commit 29aa172391

View file

@ -81,7 +81,7 @@ sub search ($self)
status => 200 status => 200
) if $q eq ""; ) if $q eq "";
$q =~ s/[\%_\\]/\\$&/g; $q =~ s/[%\\_]/\\$&/g;
$q .= '%'; $q .= '%';
my %attrs = ( my %attrs = (
$search_opts{TagCountView}->%*, $search_opts{TagCountView}->%*,
@ -95,7 +95,7 @@ sub search ($self)
display => $_->display, display => $_->display,
count => $_->count, count => $_->count,
}, $self->schema->resultset("TagCountView") }, $self->schema->resultset("TagCountView")
->search({name => {-like => $q}}, \%attrs); ->search({name => \["LIKE ? ESCAPE '\\'", $q]}, \%attrs);
return $self->render(json => {tags => [@tags]}); return $self->render(json => {tags => [@tags]});
} }