Skip to content

Illegal mix of collations in urlrewrite module #40189

@indykoning

Description

@indykoning

Preconditions and environment

  • Magento version: 2.4.8-p2

Steps to reproduce

  1. Navigate to your magento store with a urlencoded non-utf8 character https://example.com/%C0, another example with a utf8 character but it being an emoj https://example.com/🔎
  2. See as an error gets produced because invalid characters are put into the mysql query

Expected result

A 404 page, or redirect if it has been set

Actual result

An error gets thrown:

SQLSTATE[HY000]: General error: 1271 Illegal mix of collations for operation ' IN ', query was: SELECT `url_rewrite`.* FROM `url_rewrite` WHERE (`request_path` IN ('%C0', '%C0/', '�', '�/')) AND (`store_id` IN ('1'))

Additional information

This error comes from: vendor/magento/module-url-rewrite/Model/Storage/DbStorage.php@doFindOneByData

Changing the code like this, does fix it. Question is, is it the right way?

-            $decodedRequestPath = urldecode($requestPath);
+            $decodedRequestPath = mb_convert_encoding(urldecode($requestPath), 'UTF-8');

This replaces those unknown characters to ?

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: ExceptionIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Reported on 2.4.8-p2Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions