Comments (7)
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.
+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.
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.
@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.
@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.
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.
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)
- Return types inaccurate HOT 5
- ServerRequest: Header with value "0" discarded HOT 6
- Segfault in PHP 7.3.0 when instantiating HtmlResponse in Built-in Web Server HOT 13
- Version 2.0.2 breaks on Apache HOT 5
- get an exeption from ServerRequestFactory::fromGlobals if i make get req without variables HOT 4
- Header error with Docker container usage HOT 12
- ServerRequestFactory::fromGlobals() breaking on windows x64 HOT 3
- UTF-8 URIs are broken by parse_url when locale is set HOT 6
- Empty header check breaking change HOT 4
- Array cookies not parser properly HOT 1
- marshallHttps incorrectly detects HTtPS-connection
- Generators are not supported for JSON responses. HOT 1
- BUG: marshalHeadersFromSapi assume all SERVER keys are strings HOT 1
- LTS Version 1.7 is missing a security fix HOT 5
- PHP Parse error: syntax error, unexpected '?', expecting variable @ marshal_uri_from_sapi.php on line 83 HOT 7
- Can UploadedFile extend SplFileInfo ? HOT 12
- PhpInputStream's getSize function is Wrong! HOT 4
- Probably an incorrect test case testAuthorityIsPrefixedByDoubleSlashIfPresent in UriTest.php HOT 1
- PHP Fatal error: require(): Failed opening required zendframework/zend-diactoros/src/functions/create_uploaded_file.php HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zend-diactoros.