Skip to content
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

[BUG]: Phalcon route Exception when uri contains arabic letters #15102

Closed
ajaajaaMohameda opened this issue Jul 6, 2020 · 1 comment · Fixed by #15162
Closed

[BUG]: Phalcon route Exception when uri contains arabic letters #15102

ajaajaaMohameda opened this issue Jul 6, 2020 · 1 comment · Fixed by #15162
Assignees
Labels
bug A bug report

Comments

@ajaajaaMohameda
Copy link

Describe the bug
Hello, we are working on a project where we have to search using arabic letters, when we have a uri like this one: "/client/محمد" the notFoundHandler get executed which means the route was not matched

To Reproduce

use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Micro;

$container = new FactoryDefault();

$application = new Micro($container);

$application->get(
    "/client/{search:\p{Xan}{0,20}}",
    function ($search) {
        echo "Welcome $search!";
    }
);

$application->notFound(function () use ($application) {
    echo "the route was not matched";
    var_dump($application->router->getRoutes()[0]->getCompiledPattern());
});

$application->handle(urldecode($_SERVER["REQUEST_URI"]));

Expected behavior
given the regular expression we use, the route must match if the uri is "/client/محمد"

Details

  • Phalcon version:
phalcon
Phalcon is a full stack PHP framework, delivered as a PHP extension, offering lower resource consumption and high performance.
phalcon => enabled
Author => Phalcon Team and contributors
Version => 4.0.6
Build Date => Jun 12 2020 08:14:19
Powered by Zephir => Version 0.12.17-6724dbf

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.case_insensitive_column_map => Off => Off
phalcon.orm.cast_last_insert_id_to_int => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.exception_on_failed_metadata_save => On => On
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.warning.enable => On => On
  • PHP Version:
PHP 7.2.31 (cli) (built: Jun  9 2020 15:16:26) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
  • Operating System:
    Kubuntu 18.04
  • Installation type: installing via package manager
  • Server: Apache

Additional context
We took a look at the phalcon github repository and we found the compilePattern (string! pattern) function which is located in https://github.com/phalcon/cphalcon/blob/master/phalcon/Cli/Router/Route.zep does not add the unicode regex delimiters 'u',

/**
* Replaces placeholders from pattern returning a valid PCRE regular
* expression
*/
public function compilePattern(string! pattern) -> string
{
.....
/**
* Check if the pattern has parentheses or square brackets in order to
* add the regex delimiters
*/
**if memstr(pattern, "(") || memstr(pattern, "[") {
return "#^" . pattern . "$#";
}**

return pattern;
}

however in older versions like https://github.com/phalcon/cphalcon/blob/3.4.x/phalcon/mvc/router/route.zep it does

  /**
* Replaces placeholders from pattern returning a valid PCRE regular expression
*/
public function compilePattern(string! pattern) -> string
{
..................

// Check if the pattern has parentheses in order to add the regex delimiters
if memstr(pattern, "(") {
return "#^" . pattern . "$#u";
}

// Square brackets are also checked
if memstr(pattern, "[") {
return "#^" . pattern . "$#u";
}

return pattern;
}
@ajaajaaMohameda ajaajaaMohameda added bug A bug report status: unverified Unverified labels Jul 6, 2020
zsilbi added a commit that referenced this issue Sep 30, 2020
@zsilbi zsilbi added 4.1.0 and removed status: unverified Unverified labels Sep 30, 2020
@zsilbi zsilbi self-assigned this Sep 30, 2020
@zsilbi zsilbi linked a pull request Sep 30, 2020 that will close this issue
4 tasks
zsilbi added a commit to zsilbi/cphalcon that referenced this issue Oct 5, 2020
@zsilbi
Copy link
Member

zsilbi commented Oct 5, 2020

Fixed in #15162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants