Also add and update some tests. Change the semantic a little, because for filesytem paths symlinks complicate things. See the comments in the code for detail. Fix trac tickets #8813 and 8814. (cherry picked from commit 1201687da268c11459891a80ca1972aeaca8db88)