generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 73
fix: use Path.toUri() to handle WSL paths correctly #1378
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
Open
tim-sh
wants to merge
8
commits into
redhat-developer:main
Choose a base branch
from
tim-sh:feat/wslSupport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−6
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33853d3
fix: use Path.toUri() to handle WSL paths correctly
tim-sh a00d374
test: soften assertion to refer to the four slashes only
tim-sh 409c48a
chore: use util method throughout
tim-sh 3dd90d9
test: add test for paths with spaces
tim-sh af18652
refactor: method overload
tim-sh 6859b8e
docs: header and javadoc
tim-sh 574323f
fix: handle edge cases in URI conversion
tim-sh ae90356
test: split URI tests for Windows resp. Unix
tim-sh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/test/java/com/redhat/devtools/lsp4ij/LSPIJUtils_toUriTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2024 Red Hat, Inc. | ||
| * Distributed under license by Red Hat, Inc. All rights reserved. | ||
| * This program is made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, | ||
| * and is available at http://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| * SAP SE - additional test cases | ||
| ******************************************************************************/ | ||
| package com.redhat.devtools.lsp4ij; | ||
tim-sh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.condition.EnabledOnOs; | ||
| import org.junit.jupiter.api.condition.OS; | ||
|
|
||
| import java.io.File; | ||
| import java.net.URI; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
|
|
||
| /** | ||
| * Tests for {@link LSPIJUtils#toUri(File)} method. | ||
| */ | ||
| public class LSPIJUtils_toUriTest { | ||
|
|
||
| @Test | ||
| @EnabledOnOs(OS.WINDOWS) | ||
| void testToUriWithWslPath() { | ||
| // Given: Create a File object from a UNC path string | ||
| // Note: File object may normalize the path, so we test with the actual behavior | ||
| String wslPath = "\\\\wsl$\\Ubuntu\\home\\user\\project\\file.txt"; | ||
| File wslFile = new File(wslPath); | ||
|
|
||
| // When | ||
| URI resultUri = LSPIJUtils.toUri(wslFile); | ||
|
|
||
| // Then | ||
| assertNotNull(resultUri); | ||
| assertEquals("file", resultUri.getScheme()); | ||
|
|
||
| // The URI should either: | ||
| // 1. Have authority="wsl$" and path="/Ubuntu/home/user/project/file.txt" (correct UNC handling) | ||
| // 2. Or at minimum, not produce the old broken format with 4 slashes | ||
| String uriString = resultUri.toString(); | ||
| assertNotNull(uriString); | ||
|
|
||
| // Verify it doesn't have the broken 4-slash format | ||
| if (uriString.contains("file:////")) { | ||
| fail("URI should not contain file://// (broken UNC format): " + uriString); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnOs(OS.WINDOWS) | ||
| void testToUriWithLocalPathOnWindows() { | ||
| // Given | ||
| File localFile = new File("C:\\Users\\user\\project\\file.txt"); | ||
|
|
||
| // When | ||
| URI resultUri = LSPIJUtils.toUri(localFile); | ||
|
|
||
| // Then | ||
| assertNotNull(resultUri); | ||
| assertEquals("file", resultUri.getScheme()); | ||
| assertEquals("/C:/Users/user/project/file.txt", resultUri.getPath()); | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnOs({OS.LINUX, OS.MAC}) | ||
| void testToUriWithLocalPathOnUnix() { | ||
| // Given | ||
| File localFile = new File("/home/user/project/file.txt"); | ||
|
|
||
| // When | ||
| URI resultUri = LSPIJUtils.toUri(localFile); | ||
|
|
||
| // Then | ||
| assertNotNull(resultUri); | ||
| assertEquals("file", resultUri.getScheme()); | ||
| assertEquals("/home/user/project/file.txt", resultUri.getPath()); | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnOs(OS.WINDOWS) | ||
| void testToUriWithSpacesOnWindows() { | ||
| // Given | ||
| File fileWithSpaces = new File("C:\\Users\\user name\\project name\\file.txt"); | ||
|
|
||
| // When | ||
| URI resultUri = LSPIJUtils.toUri(fileWithSpaces); | ||
|
|
||
| // Then | ||
| assertNotNull(resultUri); | ||
| assertEquals("file", resultUri.getScheme()); | ||
| assertEquals("/C:/Users/user%20name/project%20name/file.txt", resultUri.getRawPath()); | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnOs({OS.LINUX, OS.MAC}) | ||
| void testToUriWithSpacesOnUnix() { | ||
| // Given | ||
| File fileWithSpaces = new File("/home/user name/project name/file.txt"); | ||
|
|
||
| // When | ||
| URI resultUri = LSPIJUtils.toUri(fileWithSpaces); | ||
|
|
||
| // Then | ||
| assertNotNull(resultUri); | ||
| assertEquals("file", resultUri.getScheme()); | ||
| assertEquals("/home/user%20name/project%20name/file.txt", resultUri.getRawPath()); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment Hich explains why path is used by adding in comments some url sample