php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #69263 dirname() removes only some double-slashes
Submitted: 2015-03-19 11:41 UTC Modified: 2015-03-19 19:37 UTC
From: marc at gutt dot it Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.4.38 OS: Debian
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: marc at gutt dot it
New email:
PHP Version: OS:

 

 [2015-03-19 11:41 UTC] marc at gutt dot it
Description:
------------
---
From manual page: http://www.php.net/function.dirname
---

dirname() removes ending double slash, but does not replace double-slash generally. It think the ending "//" should become "/" as this is the parent.

Test script:
---------------
<?php
echo dirname('http://example.com/foo/bar//index.php') . PHP_EOL;
//returns: http://example.com/foo/bar

echo dirname('http://example.com//foo//bar//index.php') . PHP_EOL;
//returns: http://example.com//foo//bar
?>


Expected result:
----------------
I would expect in both cases one ending slash:
<?php
echo dirname('http://example.com/foo/bar//index.php') . PHP_EOL;
//returns: http://example.com/foo/bar/

echo dirname('http://example.com//foo//bar//index.php') . PHP_EOL;
//returns: http://example.com//foo//bar/
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-19 19:37 UTC] cmb@php.net
-Status: Open +Status: Not a bug
 [2015-03-19 19:37 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Note, that dirname() is supposed to work on paths, and is not
necessarily suited for general URIs.

Also note, that the double slashes in your examples are actually
errors (except the double slashes after the colon following the
protocol).
 [2015-04-01 14:27 UTC] marc at gutt dot it
Of course this is not a valid path, but sometimes this happens and the OS should ignore multiple slashes at all.

But finally dirname() should remove them or not and not return a mix of both.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC