Sometimes File::getChildFile() returns a wrong path


#1

File("/moose/fish").getChildFile("…/…/foo.txt") is expected to produce “/foo.txt”, but actually it returns “/moose/foo.txt”.
This problem seems to occur when it is called with the relative path via root directory and not to occur on Windows.

Here is my fix. Will it cause any side effect?

            while (relativePath[0] == T('.'))
            {
                if (relativePath[1] == T('.'))
                {
                    if (relativePath [2] == 0 || relativePath[2] == separator)
                    {
                        const int lastSlash = path.lastIndexOfChar (separator);
// [original code]
//                      if (lastSlash > 0)
// [/original code]
// [fixed code]
                        if (lastSlash >= 0)
// [/fixed code]
                            path = path.substring (0, lastSlash);

                        relativePath = relativePath.substring (3);
                    }
                    else
                    {
                        break;
                    }
                }
                else if (relativePath[1] == separator)
                {
                    relativePath = relativePath.substring (2);
                }
                else
                {
                    break;
                }
            }

#2

I …think… that’s right. It’s one of those nasty bits of code where it feels like there might be a side-effect, but I just can’t see what it could be. I’ll go with your solution though, thanks!