Skip to content

Conversation

@pimterry
Copy link
Contributor

@pimterry pimterry commented Dec 9, 2021

Previously, on Windows and Linux (comment here was incorrect) these tests failed if the path contained spaces, because the err.source property used %20 instead of a literal space. This happens because internal URL-encoded path representations are attached directly to the error, instead of the actual path.

While this was commented out as a test error, this is actually a real bug - errors referencing paths all contained unexpectedly encoded strings.

(Pro-tip: store all your code in a local folder with spaces, and it's super easy to catch these issues before they become actual bugs that seriously break things. Easy to do in CI too!)

This change ensures that the path representations are at least decoded correctly before any errors are thrown, so that clear path strings are returned.

It would be possible to go further and use url.toFileSystemPath to fully transform the URL-formatted path into a standard platform-specific filesystem path, but that's a bigger change, we could be a breaking change for some use cases, e.g. because it would change from unix to Windows paths on Windows.

Previously, on Windows and Linux (comment here was incorrect) these tests failed if the path contained spaces, because the err.source property used %20 instead of a literal space. This happens because internal path representations are used, instead of the actual path. This change ensures that the path representations are at least decoded correctly before any errors are thrown, ensuring that usable paths are returned. It is possible to go further and use url.toFileSystemPath to fully transform the URL-formatted path into a standard platform-specific filesystem path, but this could be a breaking change for some use cases, because it would change from unix to Windows paths on Windows, for example.
Copy link
Member

@philsturgeon philsturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks Tim!

@philsturgeon philsturgeon merged commit b6f968b into APIDevTools:main Dec 9, 2021
@github-actions
Copy link

🎉 This PR is included in version 9.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants