Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use URI.fsPath to get valid Windows paths #2

Merged
merged 1 commit into from
May 1, 2023

Conversation

itsananderson
Copy link
Contributor

After some debugging, I've figured out the Windows issue I've been encountering.

Calling URI.path for a file:// URI returns a string that starts with a leading slash, so for example:

"file:///c%3A/Users/test/some-file.md"

Would become:

"/C:/Users/test/some-file.md"

That path is not a valid Windows path, so calls to fs.existsSync etc. will fail even though that target Markdown file exists on disk.

After digging around a little in vscode-uri, I found that they have a separate fsPath property which seems to behave how we actually want it to behave, returning a string like:

"C:\\Users\\test\\some-file.md"

While debugging this, I also found that there aren't actually any test fixtures for valid markdown doc links (which explains why the tests were green on Windows). I added one test fixture for a valid cross-doc link to help verify that this actually fixes something.

@itsananderson itsananderson requested a review from a team as a code owner March 9, 2023 05:01
@@ -119,36 +119,36 @@ export class DocsWorkspace implements IWorkspace {
}

hasMarkdownDocument(resource: URI) {
const relativePath = path.relative(URI.file(this.root).path, resource.path);
const relativePath = path.relative(path.resolve(this.root), resource.fsPath);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One change I made here was to just use path.resolve to get an absolute path for the root dir. I think that's easier to reason about than URI's handling of relative paths, but I'm happy to switch this to URI.file(this.root).fsPath instead if that's preferred.

@dsanders11 dsanders11 changed the title fix: Use URI.fsPath to get valid Windows paths fix: use URI.fsPath to get valid Windows paths Mar 13, 2023
@dsanders11 dsanders11 self-assigned this Mar 13, 2023
@dsanders11
Copy link
Member

Thanks @itsananderson. LGTM, but I'm going to hold off on merging for a few days and hopefully get the npm package issues resolved so it will actually publish on merge.

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

LGTM.

Following @dsanders11's lead from yesterday of not hitting "approve" since he mentioned wanting to hold off on merging this for a few days, and if this shows up as green it might get merged by accident

@dsanders11 dsanders11 merged commit 4ae000d into electron:main May 1, 2023
@itsananderson itsananderson deleted the fix-windows-paths branch May 1, 2023 23:14
@continuous-auth
Copy link

🎉 This PR is included in version 1.0.1 🎉

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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants