Merge pull request #988 from LORgames/ssurtees/pathNormalizationFix

Fixed a bug with normalizing paths that contain dot folders
This commit is contained in:
Samuel Surtees 2018-02-05 21:56:03 +10:00 committed by GitHub
commit 0eda22c602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -35,7 +35,8 @@ static void* normalize_substring(const char* str, const char* endPtr, char* writ
ptr = writePtr - 3;
while (ptr >= writeBegin) {
if (ptr[0] == '/' && ptr[1] != '.' && ptr[2] != '.') {
/* break on '/' except when it's '/../' */
if (ptr[0] == '/' && !(ptr[1] == '.' && ptr[2] == '.' && ptr[3] == '/')) {
writePtr -= writePtr - ptr;
/* special fix for cases, when '..' is the last chars in path i.e. d:\game\.., this should be converted into d:\,

View File

@ -683,4 +683,13 @@
function suite.normalize_legitimateDots()
test.isequal("d:/test/test..test", path.normalize("d:/test/test..test"))
test.isequal("d:/test..test/test", path.normalize("d:/test..test/test"))
test.isequal("d:/test/.test", path.normalize("d:/test/.test"))
test.isequal("d:/.test", path.normalize("d:/test/../.test"))
test.isequal("d:/test", path.normalize("d:/test/.test/.."))
test.isequal("d:/test/..test", path.normalize("d:/test/..test"))
test.isequal("d:/..test", path.normalize("d:/test/../..test"))
test.isequal("d:/test", path.normalize("d:/test/..test/.."))
test.isequal("d:/test/.test", path.normalize("d:/test/..test/../.test"))
test.isequal("d:/test/..test/.test", path.normalize("d:/test/..test/test/../.test"))
test.isequal("d:/test", path.normalize("d:/test/..test/../.test/.."))
end