I wrote:
> On reflection I think that what we need to do is fix it so that it only
> strips "../" from the tail string when there is a directory name
> available to be stripped from the head string. Otherwise just stop
> trimming.
Actually, there is a much simpler fix: don't let it strip ".." at all.
There is no correctness reason to do that, and as for cosmetics, callers
who care can use canonicalize_path() to remove ".." correctly. (AFAICS,
all existing callers of join_path_components already do so anyway.)
regards, tom lane