don't construct invalid paths
tear this logic apart a bit to make it easier to comprehend. previously it was trying to be too smart for its own good.
the previous code would url.todisplaystring (this returns a url if the input was an url - e.g. file:///foo) but then used that with fromLocalFile (which prepends file:/) ultimately ending up with file:file://foo.
instead let's manipulate the path proper-like. append to the path(), then simply pass along the url, no localfile conversion necessary at all