jamesbrowder / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Files.simplifyPath("./a") -> "/a" #716

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
assertEquals("a", Files.simplifyPath("./a"));

What version of the product are you using? On what operating system?
commit 64b32d8a33f284adc71e423515b93fa83694fe97
Date:   Thu Sep 15 10:25:07 2011 -0400

I implemented a test hack to find the problems with simplifyPath. It creates a 
path string from the characters [a-c./] and checks that the canonical path does 
not change due to simplifyPath.

assertEquals(new File(path).getCanonicalPath(), new 
File(Files.simplifyPath(path)).getCanonicalPath());

Sadly, this can't be used in an ordinary test. It depends on the current 
working directory for relative paths and produces invalids paths (for example 
"a../b" produces an IOException).

One way to increase the test coverage could be to create canonical paths (a, 
a/b, ../a, ..) and add changes that can be simplified to the canonical path:
simplyPath(“x/../” + relativePath) == relativePath
simplyPath(path + “/x/../”) == path
simplyPath(lpath + “/x/../” + rpath) == lpath + rpath
simplyPath(“/” + absolutePath) == absolutePath
simplyPath(“./” + relativePath) == relativePath
simplyPath(path + “/./”) == path
simplyPath(lpath + “/./” + rpath) == lpath + rpath

The changes to the canonical paths can also be generated “/x/../” is 
equivalent to “/x/y/../../”, “/x/../y/../”, etc.

If someone is interested I could implement this test.

Original issue reported on code.google.com by thomas.a...@gmail.com on 16 Sep 2011 at 7:51

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 17 Sep 2011 at 3:09

GoogleCodeExporter commented 9 years ago
According to the attached test the following outputs values are incorrect 
(Format input value, expected output, actual output). Mostly hidden files are 
not treated correctly.

in:>./a< expected:>a< out:>/a<
in:>./a/b< expected:>a/b< out:>/ab<
in:>./a/b/c< expected:>a/b/c< out:>/abc<
in:>/.a< expected:>/.a< out:>//<
in:>/.a/.b< expected:>/.a/.b< out:>//.b<
in:>/.a/.b/.c< expected:>/.a/.b/.c< out:>//.b.c<
in:>/./a< expected:>/a< out:>//a<
in:>.//a/b< expected:>/a/b< out:>/ab<
in:>/./a/b< expected:>/a/b< out:>//ab<
in:>.//a/b/c< expected:>/a/b/c< out:>/abc<
in:>/./a/b/c< expected:>/a/b/c< out:>//abc<
in:>.a< expected:>.a< out:>/<
in:>.a/.b< expected:>.a/.b< out:>/.b<
in:>.a/.b/.c< expected:>.a/.b/.c< out:>/.b.c<
in:>/..a< expected:>/..a< out:>//a<
in:>/..a/..b< expected:>/..a/..b< out:>//a..b<
in:>/..a/..b/..c< expected:>/..a/..b/..c< out:>//a..b..c<
in:>..a< expected:>..a< out:>/a<
in:>..a/..b< expected:>..a/..b< out:>/a..b<
in:>..a/..b/..c< expected:>..a/..b/..c< out:>/a..b..c<
in:>/...a< expected:>/...a< out:>//.a<
in:>/...a/...b< expected:>/...a/...b< out:>//.a...b<
in:>/...a/...b/...c< expected:>/...a/...b/...c< out:>//.a...b...c<
in:>...a< expected:>...a< out:>/.a<
in:>...a/...b< expected:>...a/...b< out:>/.a...b<
in:>...a/...b/...c< expected:>...a/...b/...c< out:>/.a...b...c<
in:>..//..//..//a//< expected:>../../../a< out:>../..../a<
in:>..///..///..///a///< expected:>../../../a< out:>../..../a<
in:>..//..//..//a//b//< expected:>../../../a/b< out:>../..../a/b<
in:>..///..///..///a///b///< expected:>../../../a/b< out:>../..../a/b<
in:>..//..//..//a//b//c//< expected:>../../../a/b/c< out:>../..../a/b/c<
in:>..///..///..///a///b///c///< expected:>../../../a/b/c< out:>../..../a/b/c<
in:>/...< expected:>/...< out:>//<
in:>/.../...< expected:>/.../...< out:>//...<
in:>/.../.../...< expected:>/.../.../...< out:>//......<
in:>...< expected:>...< out:>/<
in:>.../...< expected:>.../...< out:>/...<
in:>.../.../...< expected:>.../.../...< out:>/......<
in:>/....< expected:>/....< out:>/<
in:>/..../....< expected:>/..../....< out:>/....<
in:>/..../..../....< expected:>/..../..../....< out:>/..../....<
in:>....< expected:>....< out:><
in:>..../....< expected:>..../....< out:>....<
in:>..../..../....< expected:>..../..../....< out:>..../....<
in:>/.....< expected:>/.....< out:>//...<
in:>/...../.....< expected:>/...../.....< out:>//........<
in:>/...../...../.....< expected:>/...../...../.....< out:>//.............<
in:>.....< expected:>.....< out:>/...<
in:>...../.....< expected:>...../.....< out:>/........<
in:>...../...../.....< expected:>...../...../.....< out:>/.............<
in:>/......< expected:>/......< out:>//....<
in:>/....../......< expected:>/....../......< out:>//..........<
in:>/....../....../......< expected:>/....../....../......< 
out:>//................<
in:>......< expected:>......< out:>/....<
in:>....../......< expected:>....../......< out:>/..........<
in:>....../....../......< expected:>....../....../......< 
out:>/................<

Original comment by thomas.a...@gmail.com on 19 Sep 2011 at 4:59

Attachments:

GoogleCodeExporter commented 9 years ago
Very helpful, thanks. This should be fixed in 10.0-rc3.

Original comment by kevinb@google.com on 20 Sep 2011 at 8:14

GoogleCodeExporter commented 9 years ago

Original comment by fry@google.com on 22 Sep 2011 at 9:38

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09