PartialSearchFilter: ESCAPE '\' causes ORA-01425 on Oracle
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 62/100
調査の方向性
まず ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter を見つけ、2つの LIKE 式と formatLikeValue() を読みます。設定可能なエスケープ文字にするか Oracle 固有の処理にするかを選ぶ前に、api-platform/doctrine-orm と api-platform/symfony でフィルターがどのように構築されているかを確認します。完了条件は、大文字と小文字を区別する両方のモードで Oracle が受け入れる ESCAPE 句が生成され、%、_、およびエスケープ文字が一貫してエスケープされることです。
索引モデルが issue の本文から書いたものです。
説明
API Platform version(s) affected: 4.3.10
(api-platform/doctrine-orm / api-platform/symfony)
Description
ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter generates SQL LIKE expressions with ESCAPE '\'.
On Oracle this fails with:
ORA-01425: escape character must be character string of length 1
In the executed SQL the escape clause appears as ESCAPE '\\' / ESCAPE '\\\\' (depending on logging), which Oracle rejects because the escape character is not a single-character string.
This affects both case-sensitive and case-insensitive modes, since both append the same ESCAPE '\' clause.
How to reproduce
- Use API Platform 4.3.x with Doctrine ORM on an Oracle database.
- Configure a collection operation with
PartialSearchFilter:
use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\QueryParameter;
new GetCollection(
uriTemplate: '/items',
parameters: [
'name' => new QueryParameter(
filter: new PartialSearchFilter(),
property: 'name',
),
],
)
- Call:
GET /items?name=test
- Observe the generated SQL containing something like:
LOWER(o.name) LIKE LOWER(:name_p1) ESCAPE '\\'
and Oracle raising ORA-01425.
Relevant code in PartialSearchFilter:
$field.' LIKE :'.$parameterName.' ESCAPE \'\\\''
// and
'LOWER('.$field.') LIKE LOWER(:'.$parameterName.') ESCAPE \'\\\''
with:
private function formatLikeValue(string $value): string
{
return '%'.addcslashes($value, '\\%_').'%';
}
Possible Solution
Make the escape character configurable (constructor option), and/or use a DB-agnostic escape character that Oracle accepts (e.g. !), updating both:
- the
ESCAPE '...'SQL clause formatLikeValue()escaping of%,_, and the escape character itself
Example approach:
public function __construct(
private readonly bool $caseSensitive = false,
private readonly string $escapeCharacter = '\\',
) {}
Then for Oracle consumers:
new PartialSearchFilter(escapeCharacter: '!')
Alternatively, detect the database platform and choose a safe default escape character for Oracle.
Additional Context
- Database: Oracle
- Error:
Doctrine\DBAL\Exception\DriverExceptionwrappingORA-01425 - Workaround used locally: custom filter based on
PartialSearchFilter, replacing\with!as escape character in both the SQLESCAPEclause and value escaping. - Same issue likely impacts any environment where
ESCAPE '\'is not treated as a single-character literal.
- 主要言語
- PHP
- スター
- 2.6k
- フォーク
- 982
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 59
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/core のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
api-platform/core#8573 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
api-platform/core#8571 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
api-platform/core#8564 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
api-platform/core#8495 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
api-platform/core#8471 ·
api-platform/core の issue をすべて見る
似ている issue
-
tooling
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
UX
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ProfessionalWiki/NeoWiki#1525 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug customer-reported
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
MagnaCapax/PMSS#949 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Automattic/static-site-importer#1829 ·