Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
8071657c
Commit
8071657c
authored
Nov 18, 2014
by
Lukas Reschke
Browse files
Merge pull request #12234 from owncloud/normalizepath-absolute-tests
Add tests for normalizePath() with absolute paths on windows
parents
944cd327
ccc10011
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/lib/files/filesystem.php
View file @
8071657c
...
...
@@ -75,71 +75,112 @@ class Filesystem extends \Test\TestCase {
$this
->
assertEquals
(
'folder'
,
$internalPath
);
}
public
function
testNormalize
()
{
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
''
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/'
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/'
,
false
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'//'
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'//'
,
false
));
$this
->
assertEquals
(
'/path'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/path/'
));
$this
->
assertEquals
(
'/path/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/path/'
,
false
));
$this
->
assertEquals
(
'/path'
,
\
OC\Files\Filesystem
::
normalizePath
(
'path'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo//bar/'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo//bar/'
,
false
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo////bar'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/////bar'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/bar/.'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/bar/./'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/bar/./'
,
false
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/bar/./.'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/bar/././'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/bar/././'
,
false
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/./bar/'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/./bar/'
,
false
));
$this
->
assertEquals
(
'/foo/.bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/.bar/'
));
$this
->
assertEquals
(
'/foo/.bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/.bar/'
,
false
));
$this
->
assertEquals
(
'/foo/.bar/tee'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/.bar/tee'
));
// normalize does not resolve '..' (by design)
$this
->
assertEquals
(
'/foo/..'
,
\
OC\Files\Filesystem
::
normalizePath
(
'/foo/../'
));
if
(
class_exists
(
'Patchwork\PHP\Shim\Normalizer'
))
{
$this
->
assertEquals
(
"/foo/bar
\xC3\xBC
"
,
\
OC\Files\Filesystem
::
normalizePath
(
"/foo/baru
\xCC\x88
"
));
public
function
normalizePathData
()
{
return
array
(
array
(
'/'
,
''
),
array
(
'/'
,
'/'
),
array
(
'/'
,
'//'
),
array
(
'/'
,
'/'
,
false
),
array
(
'/'
,
'//'
,
false
),
array
(
'/path'
,
'/path/'
),
array
(
'/path/'
,
'/path/'
,
false
),
array
(
'/path'
,
'path'
),
array
(
'/foo/bar'
,
'/foo//bar/'
),
array
(
'/foo/bar/'
,
'/foo//bar/'
,
false
),
array
(
'/foo/bar'
,
'/foo////bar'
),
array
(
'/foo/bar'
,
'/foo/////bar'
),
array
(
'/foo/bar'
,
'/foo/bar/.'
),
array
(
'/foo/bar'
,
'/foo/bar/./'
),
array
(
'/foo/bar/'
,
'/foo/bar/./'
,
false
),
array
(
'/foo/bar'
,
'/foo/bar/./.'
),
array
(
'/foo/bar'
,
'/foo/bar/././'
),
array
(
'/foo/bar/'
,
'/foo/bar/././'
,
false
),
array
(
'/foo/bar'
,
'/foo/./bar/'
),
array
(
'/foo/bar/'
,
'/foo/./bar/'
,
false
),
array
(
'/foo/.bar'
,
'/foo/.bar/'
),
array
(
'/foo/.bar/'
,
'/foo/.bar/'
,
false
),
array
(
'/foo/.bar/tee'
,
'/foo/.bar/tee'
),
// Windows paths
array
(
'/'
,
''
),
array
(
'/'
,
'\\'
),
array
(
'/'
,
'\\'
,
false
),
array
(
'/'
,
'\\\\'
),
array
(
'/'
,
'\\\\'
,
false
),
array
(
'/path'
,
'\\path'
),
array
(
'/path'
,
'\\path'
,
false
),
array
(
'/path'
,
'\\path\\'
),
array
(
'/path/'
,
'\\path\\'
,
false
),
array
(
'/foo/bar'
,
'\\foo\\\\bar\\'
),
array
(
'/foo/bar/'
,
'\\foo\\\\bar\\'
,
false
),
array
(
'/foo/bar'
,
'\\foo\\\\\\\\bar'
),
array
(
'/foo/bar'
,
'\\foo\\\\\\\\\\bar'
),
array
(
'/foo/bar'
,
'\\foo\\bar\\.'
),
array
(
'/foo/bar'
,
'\\foo\\bar\\.\\'
),
array
(
'/foo/bar/'
,
'\\foo\\bar\\.\\'
,
false
),
array
(
'/foo/bar'
,
'\\foo\\bar\\.\\.'
),
array
(
'/foo/bar'
,
'\\foo\\bar\\.\\.\\'
),
array
(
'/foo/bar/'
,
'\\foo\\bar\\.\\.\\'
,
false
),
array
(
'/foo/bar'
,
'\\foo\\.\\bar\\'
),
array
(
'/foo/bar/'
,
'\\foo\\.\\bar\\'
,
false
),
array
(
'/foo/.bar'
,
'\\foo\\.bar\\'
),
array
(
'/foo/.bar/'
,
'\\foo\\.bar\\'
,
false
),
array
(
'/foo/.bar/tee'
,
'\\foo\\.bar\\tee'
),
// Absolute windows paths NOT marked as absolute
array
(
'/C:'
,
'C:\\'
),
array
(
'/C:/'
,
'C:\\'
,
false
),
array
(
'/C:/tests'
,
'C:\\tests'
),
array
(
'/C:/tests'
,
'C:\\tests'
,
false
),
array
(
'/C:/tests'
,
'C:\\tests\\'
),
array
(
'/C:/tests/'
,
'C:\\tests\\'
,
false
),
// normalize does not resolve '..' (by design)
array
(
'/foo/..'
,
'/foo/../'
),
array
(
'/foo/..'
,
'\\foo\\..\\'
),
);
}
/**
* @dataProvider normalizePathData
*/
public
function
testNormalizePath
(
$expected
,
$path
,
$stripTrailingSlash
=
true
)
{
$this
->
assertEquals
(
$expected
,
\
OC\Files\Filesystem
::
normalizePath
(
$path
,
$stripTrailingSlash
));
}
public
function
normalizePathWindowsAbsolutePathData
()
{
return
array
(
array
(
'C:/'
,
'C:\\'
),
array
(
'C:/'
,
'C:\\'
,
false
),
array
(
'C:/tests'
,
'C:\\tests'
),
array
(
'C:/tests'
,
'C:\\tests'
,
false
),
array
(
'C:/tests'
,
'C:\\tests\\'
),
array
(
'C:/tests/'
,
'C:\\tests\\'
,
false
),
);
}
/**
* @dataProvider normalizePathWindowsAbsolutePathData
*/
public
function
testNormalizePathWindowsAbsolutePath
(
$expected
,
$path
,
$stripTrailingSlash
=
true
)
{
if
(
!
\
OC_Util
::
runningOnWindows
())
{
$this
->
markTestSkipped
(
'This test is Windows only'
);
}
$this
->
assertEquals
(
$expected
,
\
OC\Files\Filesystem
::
normalizePath
(
$path
,
$stripTrailingSlash
,
true
));
}
public
function
testNormalizeWindowsPaths
()
{
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
''
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\'
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\'
,
false
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\\\'
));
$this
->
assertEquals
(
'/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\\\'
,
false
));
$this
->
assertEquals
(
'/path'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\path'
));
$this
->
assertEquals
(
'/path'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\path'
,
false
));
$this
->
assertEquals
(
'/path'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\path\\'
));
$this
->
assertEquals
(
'/path/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\path\\'
,
false
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\\\bar\\'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\\\bar\\'
,
false
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\\\\\\\bar'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\\\\\\\\\bar'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\bar\\.'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\bar\\.\\'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\bar\\.\\'
,
false
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\bar\\.\\.'
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\bar\\.\\.\\'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\bar\\.\\.\\'
,
false
));
$this
->
assertEquals
(
'/foo/bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\.\\bar\\'
));
$this
->
assertEquals
(
'/foo/bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\.\\bar\\'
,
false
));
$this
->
assertEquals
(
'/foo/.bar'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\.bar\\'
));
$this
->
assertEquals
(
'/foo/.bar/'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\.bar\\'
,
false
));
$this
->
assertEquals
(
'/foo/.bar/tee'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\.bar\\tee'
));
// normalize does not resolve '..' (by design)
$this
->
assertEquals
(
'/foo/..'
,
\
OC\Files\Filesystem
::
normalizePath
(
'\\foo\\..\\'
));
if
(
class_exists
(
'Patchwork\PHP\Shim\Normalizer'
))
{
$this
->
assertEquals
(
"/foo/bar
\xC3\xBC
"
,
\
OC\Files\Filesystem
::
normalizePath
(
"
\\
foo
\\
baru
\xCC\x88
"
));
public
function
testNormalizePathUTF8
()
{
if
(
!
class_exists
(
'Patchwork\PHP\Shim\Normalizer'
))
{
$this
->
markTestSkipped
(
'UTF8 normalizer Patchwork was not found'
);
}
$this
->
assertEquals
(
"/foo/bar
\xC3\xBC
"
,
\
OC\Files\Filesystem
::
normalizePath
(
"/foo/baru
\xCC\x88
"
));
$this
->
assertEquals
(
"/foo/bar
\xC3\xBC
"
,
\
OC\Files\Filesystem
::
normalizePath
(
"
\\
foo
\\
baru
\xCC\x88
"
));
}
public
function
testHooks
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment