|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63290 FILTER_FLAG_PATH_REQUIRED is true even if there is no path
Submitted: 2012-10-16 16:42 UTC Modified: 2021-07-22 12:49 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: leo at leo-unglaub dot net Assigned:
Status: Open Package: URL related
PHP Version: 5.4.7 OS: Debian Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: leo at leo-unglaub dot net
New email:
PHP Version: OS:


 [2012-10-16 16:42 UTC] leo at leo-unglaub dot net
if you validate a given url with the function filter_var and the param FILTER_VALIDATE_URL with the flag FILTER_FLAG_PATH_REQUIRED you also get true back if there is no path.

The function is happy with the result if there is a simple / at the end of the function. But thats not a valid path. A valid path would be at least 1 char after the /. I added you some examples below.

thanks and greetings

Test script:
php -r 'var_dump(filter_var("", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED));' // <- will be okay, but it's not.

php -r 'var_dump(filter_var("", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED));' // <- that would be okay.

Expected result:
filter_var() should return false if the path is not given/empty because according to the documentation if forces the requirement of a path.

Actual result:
filter_var is okay with an url if there is a / at the end.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-22 12:49 UTC]
-Type: Bug +Type: Documentation Problem
 [2021-07-22 12:49 UTC]
Well, in a strict sense you're right, but I don't think we can
change that for BC reasons.  The documentation should clarify that
FILTER_FLAG_PATH_REQUIRED also accepts URLs with an empty path
(path-empty in RFC 3986 parlance).
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 22 09:03:41 2023 UTC