Giter VIP home page Giter VIP logo

Comments (7)

freyr avatar freyr commented on August 29, 2024 1

This is not even a problem for recreating this particular case. Uri::filterPath() has type checks to return string. And preg_replace_callback that is inside might return null if some errors occurs. There is no checks for that situation and it might happen that Uri::filterPath() will return null - thus breaking contract.

In my local environment diactoros unit tests fails due to this exact problem:
this url http://example.com/тестовый_путь/ fails:

TypeError : Return value of Zend\Diactoros\Uri::filterPath() must be of the type string, null returned

And preg_last_error() return 4 which is PREG_BAD_UTF8_ERROR code.

I'm trying to find which configuration option is doing this, but i suspect that some locale configuration might do that.

However this is not even an issue as there are environments that are running with this configuration and they are affected by this TypeError issue. AFAIK throwing exception or emmiting error will be BC way of fixing that (changing return type to nullable is probably bad idea)

I could attach my php.ini configuration to maybe help recreating this issue?

from zend-diactoros.

krowinski avatar krowinski commented on August 29, 2024

+1

it's returning null because of some regexp error can we use preg_last_error to check and throw exception in filterQueryOrFragment ?

from zend-diactoros.

weierophinney avatar weierophinney commented on August 29, 2024

Can you provide example $server and/or $header arrays that demonstrate the issue, please? From there we can write a test, which will help us create a fix and prevent a future regression.

Thanks!

from zend-diactoros.

krowinski avatar krowinski commented on August 29, 2024

@weierophinney Hi, here you go

<?php
var_dump(
    preg_replace_callback(
        '/(?:[^a-zA-Z0-9_\-\.~\pL!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/u',
        static function (array $matches) {return rawurlencode($matches[0]);} ,
        ("\x21\x92")
    ), 
    preg_last_error()
);

http://sandbox.onlinephpfunctions.com/code/9d90fde0fac05f1d26c0f3310fee3e6cf2405b91

from zend-diactoros.

weierophinney avatar weierophinney commented on August 29, 2024

@krowinski I'm not asking for a patch, I'm asking for a reproduce case. I need that so I can write a unit test...

from zend-diactoros.

krowinski avatar krowinski commented on August 29, 2024

what? this is not a patch its a test how to break preg match to return null, I will fork repo and write test myself

from zend-diactoros.

krowinski avatar krowinski commented on August 29, 2024

I added to tests example that will fail preg match here

https://github.com/krowinski/zend-diactoros/commit/81085ad4528bcb25ca505b4f614a824356e02ca7

and travis will fail
https://travis-ci.org/krowinski/zend-diactoros/jobs/595632127

There was 1 error:
1) ZendTest\Diactoros\UriTest::testUtf8Path with data set #2 ('http://example.com/!�', '')
TypeError: Return value of Zend\Diactoros\Uri::filterPath() must be of the type string, null returned
/home/travis/build/krowinski/zend-diactoros/src/Uri.php:590
/home/travis/build/krowinski/zend-diactoros/src/Uri.php:466
/home/travis/build/krowinski/zend-diactoros/src/Uri.php:115
/home/travis/build/krowinski/zend-diactoros/test/UriTest.php:609

from zend-diactoros.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.