Bug #72642 [Nab]: realpath() failing to expand path
| From: | anrdaemon at freemail dot ru | Date: | Fri, 22 Jul 2016 17:30:45 +0000 |
| Subject: | Bug #72642 [Nab]: realpath() failing to expand path | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202507@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72642&edit=1
ID: 72642
User updated by: anrdaemon at freemail dot ru
Reported by: anrdaemon at freemail dot ru
Summary: realpath() failing to expand path
Status: Not a bug
Type: Bug
Package: Filesystem function related
Operating System: Windows
PHP Version: 7.1.0beta1
Block user comment: N
Private report: N
New Comment:
Did you ever read the provided test script?
Did you try to run it?
I can replace /J with /D, then you will not be able to run it without elevated privileges, but the
result would not change.
And it is funny you mentioned readlink, because 'realpath.php':
<?php
$rootdir = substr($_SERVER['SystemRoot'], 0, 3);
$tmpdir = getenv('TEMP');
shell_exec("mklink /J \"{$rootdir}home\" \"{$rootdir}Users\"");
shell_exec("mklink /J \"{$tmpdir}\\test.dir\"
\"{$rootdir}home\\Public\\Desktop\"");
$file = "{$tmpdir}\\test.dir\\desktop.ini";
$rfile = realpath($file);
printf("orig.file name: %s\n", $file);
printf("realpath(name): %s\n", $rfile);
printf("THE real name: %s\n", realpath($rfile));
printf("readlink -fe: %s\n", shell_exec("readlink -fe \"$file\""));
if($rfile != realpath($rfile))
print "Fail as is.\n";
rmdir("{$rootdir}home");
rmdir("{$tmpdir}\\test.dir");
[C:\Programs\php-7.1.0b1]$ php.cmd -f realpath.php
orig.file name: C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir\desktop.ini
realpath(name): C:\home\Public\Desktop\desktop.ini
THE real name: C:\Users\Public\Desktop\desktop.ini
readlink -fe: /c/Users/Public/Desktop/desktop.ini
Fail as is.
[C:\Programs\php-7.1.0b1]$
For your future genious resolutions, all NTFS symlinks are junctions, just with different
attributes.
Previous Comments:
------------------------------------------------------------------------
[2016-07-22 00:31:30] pajoye@php.net
Junctions are like hard link and are not resolved by realpath (or readlink).
------------------------------------------------------------------------
[2016-07-21 23:38:53] anrdaemon at freemail dot ru
Description:
------------
realpath(), according to the documentation, is supposed to unwind every symlink and relative
reference in the given string and produce an absolute and unambiguous path.
Well⦠it doesn't perform its job quite as desired.
Affected PHP versions: same behavior observed in 5.3.29, 5.6.23, 7.0.8 and 7.1.0b1.
Test script:
---------------
<?php
$rootdir = substr($_SERVER['SystemRoot'], 0, 3);
$tmpdir = getenv('TEMP');
shell_exec("mklink /J \"{$rootdir}home\" \"{$rootdir}Users\"");
shell_exec("mklink /J \"{$tmpdir}\\test.dir\"
\"{$rootdir}home\\Public\\Desktop\"");
$file = "{$tmpdir}\\test.dir\\desktop.ini";
$rfile = realpath($file);
printf("orig.file name: %s\n", $file);
printf("realpath(name): %s\n", $rfile);
printf("THE real name: %s\n", realpath($rfile));
if($rfile != realpath($rfile))
print "Fail as is.\n";
rmdir("{$rootdir}home");
rmdir("{$tmpdir}\\test.dir");
Expected result:
----------------
orig.file name: C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir\desktop.ini
realpath(name): C:\Users\Public\Desktop\desktop.ini
THE real name: C:\Users\Public\Desktop\desktop.ini
Actual result:
--------------
orig.file name: C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir\desktop.ini
realpath(name): C:\home\Public\Desktop\desktop.ini
THE real name: C:\Users\Public\Desktop\desktop.ini
Fail as is.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72642&edit=1