php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15130 pathinfo reports extension as bar/baz for /foo/bar.bar/baz
Submitted: 2002-01-20 20:27 UTC Modified: 2002-01-22 15:39 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: phpnet at cuntbubble dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.1.1 OS: FreeBSD
Private report: No CVE-ID: None
 [2002-01-20 20:27 UTC] phpnet at cuntbubble dot com
Hi,


print_r(pathinfo("/foo/bar.bar/baz"));  

Array ( 
  [dirname] => /foo/bar.bar 
  [basename] => baz 
  [extension] => bar/baz 
)
 



 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-20 22:19 UTC] irc-html@php.net
That's the correct output of pathinfo (and print_r).

See http://www.php.net/manual/en/function.pathinfo.php

Status -> Bogus
 [2002-01-20 22:29 UTC] phpnet at cuntbubble dot com
how can you possibly suggest that bar/baz

is the file extension of "/foo/bar.bar/baz"

by that logic recombining the parts gets you

/foo/bar.bar/baz.bar/baz

as the filename!


I've added a comment with a php replacement and some examples of the broken output at

http://www.php.net/manual/en/function.pathinfo.php








 [2002-01-21 03:03 UTC] torben@php.net
Reopening. It does appear that pathinfo() reacts badly if:

 a) the filename portion does not have an extension, AND
 b) one of the directories has a dot in its name.

This is because if the above conditions are met, the 
extension bit in string.c looks for the last occurrence of 
'.' in the pathname and takes anything after it as the 
file's extension. The following patch fixes the problem, if someone with enough karma would like to check it out and 
check it in (yuk yuk).


Torben


Index: string.c
===================================================================
RCS file: /repository/php4/ext/standard/string.c,v
retrieving revision 1.261
diff -u -r1.261 string.c
--- string.c	5 Jan 2002 23:49:57 -0000	1.261
+++ string.c	21 Jan 2002 07:48:41 -0000
@@ -1201,11 +1201,18 @@
 	}			
 	
 	if (argc < 2 || opt == PHP_PATHINFO_EXTENSION) {
-		char *p;
+		char *p, *last_separator;
 		int idx;
 
 		p = strrchr(Z_STRVAL_PP(path), '.');
-		if (p) {
+
+#ifdef PHP_WIN32
+		last_separator = strrchr(Z_STRVAL_PP(path), '\\');
+#else
+		last_separator = strrchr(Z_STRVAL_PP(path), '/');
+#endif
+
+		if (p && p > last_separator) {
 			idx = p - Z_STRVAL_PP(path);
 			add_assoc_stringl(tmp, "extension", Z_STRVAL_PP(path) + idx + 1, len - idx - 1, 1);
 		}


 [2002-01-22 15:05 UTC] elixer@php.net
Fixed.  Took Torben's patch one step further and only look at the basename for the file extension.

This still doesn't solve all the issues that you (phpnet@cuntbubble.com, nice email address by the way, I feel like I need to go to church just reading it :)) have with pathinfo() as you mention in your documentation note.  But it fixes this particular problem.

Closed.
 [2002-01-22 15:39 UTC] phpnet at cuntbubble dot com
great, sure glad it didn't stay as "bogus"!


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC