path: make basename and extname ignore trailing slashes

Fixes #4536