Bug #61909 [Com]: PHP realpath on Windows Case Issue

From: Date: Thu, 03 May 2012 03:16:50 +0000
Subject: Bug #61909 [Com]: PHP realpath on Windows Case Issue
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-170107@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61909&edit=1

 ID:                 61909
 Comment by:         david at panmedia dot co dot nz
 Reported by:        david at panmedia dot co dot nz
 Summary:            PHP realpath on Windows Case Issue
 Status:             Open
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Windows Vista/7
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

@laruence@php.net

Well, not always. In Windows Server 2008 it can be configured. 
http://technet.microsoft.com/en-us/library/cc725747.aspx

Also, the point of realpath is to return the canonicalized absolute pathname, but it does not.
Especially in the case of nested symlinks, as I pointed out in my other comment.

You should be able to test if a path is the same by going

if (realpath('c:\path-to-link') === realpath('C:\RealPathToTarget')) ...


Previous Comments:
------------------------------------------------------------------------
[2012-05-03 03:10:56] laruence@php.net

path in windows is case insensitive..

------------------------------------------------------------------------
[2012-05-02 17:46:25] david at panmedia dot co dot nz

On further investigation I have noticed that on Windows symlinks are only followed 1 level deep:

// F:\>mkdir link-target
// F:\>mklink /D link f:\link-target 
// F:\>mklink /D link2 f:\link

$dir = realpath('f:\link2');
var_dump($dir);

$dir = realpath($dir);
var_dump($dir);

$dir = realpath($dir);
var_dump($dir);

// string 'f:\link' (length=7)
// string 'f:\link-target' (length=14)
// string 'F:\link-target' (length=14)

------------------------------------------------------------------------
[2012-05-02 17:37:52] david at panmedia dot co dot nz

Description:
------------
I have a symlink on my Windows server which was made like this:

F:\>mkdir link-target
F:\>mklink /D link f:\link-target 

(Note the lower case f: in the symlink target)

In PHP I run this:

$dir = realpath('f:\link');
var_dump($dir);

$dir = realpath($dir);
var_dump($dir);

Which outputs:

string 'f:\link-target' (length=14)
string 'F:\link-target' (length=14)

Notice the change in case on the second realpath.

The expected output is:

string 'F:\link-target' (length=14)
string 'F:\link-target' (length=14)

Test script:
---------------
<?php
// F:\>mkdir link-target
// F:\>mklink /D link f:\link-target 

$dir = realpath('f:\link');
var_dump($dir);

$dir = realpath($dir);
var_dump($dir);

Expected result:
----------------
string 'F:\link-target' (length=14)
string 'F:\link-target' (length=14)

Actual result:
--------------
string 'f:\link-target' (length=14)
string 'F:\link-target' (length=14)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61909&edit=1


Thread (6 messages)

« previous php.bugs (#170107) next »