return path.stripHash( newPath ).replace( /[^\/]*\.[^\/*]+$/, '' )
return path.stripHash( newPath ).replace( /[?#].*/, '' ).replace( /[^\/]+$/, '' );
The former seems to assume there will always be a filename with a . after the last / in the path and that no one will put / in a query string. I'm not sure of the significance of looking for literal * characters, either.
The latter first makes sure we only have a path at the end, then removes anything that is not a directory.
This was the cause of issue #4275 for me.
Based on the docs, despite saying it's for "determining the directory portion of an URL", it's really determining something custom because there's no way a URL of only ?a=1&b=2 is a directory. So I won't bother trying to make sense of it.