Filename extensions do not contain directory separators (fix #1755)

Very simple attempt to fix #1755 by making the way filename extensions are determined slightly less naïve. I didn't touch without-ext yet (even though it is exactly as buggy) because I didn't know if it was used anywhere that depended on the naïve behavior.