Fix tests (by fixing error paths generally) when run in paths with spaces #248
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.toFileSystemPathto 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.