Skip to content

Commit 7ce3335

Browse files
tortmayrndoschek
andauthored
#47 Workspace configuration not working in Windows (#142)
* #47 Workspace configuration not working in Windows Updating the configuration via the `server/configure` endpoint does not work under Windows when used in combination with Modelserver Theia. An absolute Windows path typically contains a driver letter followed by a : (e.g c://my-workspace). So when passing absolute paths as URL parameters the `:` need to be encoded. This means we have to make sure that they are properly decoded on the server side. The easiest common point to this this the `DefaultUriHelper` class. Fixes #47 * Add additional test cases Co-authored-by: Nina Doschek <ndoschek@eclipsesource.com>
1 parent 255d964 commit 7ce3335

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

bundles/org.eclipse.emfcloud.modelserver.emf/src/org/eclipse/emfcloud/modelserver/emf/common/DefaultUriHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public URI withTrailingSeparator(final URI uri) {
6767
@Override
6868
public Optional<URI> toFileUri(final String fileUrl) {
6969
try {
70-
File file = getAbsoluteFile(fileUrl);
70+
String decodedUrl = URLDecoder.decode(fileUrl, "UTF-8");
71+
File file = getAbsoluteFile(decodedUrl);
7172
URI uri = withTrailingSeparator(URI.createFileURI(file.toURI().normalize().getPath()));
7273
return Optional.ofNullable(uri).filter(URI::isFile);
7374
} catch (NullPointerException | IllegalArgumentException | UnsupportedEncodingException e) {

tests/org.eclipse.emfcloud.modelserver.emf.tests/src/org/eclipse/emfcloud/modelserver/emf/configuration/DefaultServerConfigurationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public void normalizeWorkspaceRoot() {
4040
public void normalizeWorkspaceRootEncoded() throws UnsupportedEncodingException {
4141
serverConfiguration.setWorkspaceRoot("file:/c%3A/foo%20bar/");
4242
assertThat(serverConfiguration.getWorkspaceRootURI().toFileString(), osEndsWith("c:/foo bar/"));
43+
44+
serverConfiguration.setWorkspaceRoot("/c%3A/foo%20bar2/");
45+
assertThat(serverConfiguration.getWorkspaceRootURI().toFileString(), osEndsWith("c:/foo bar2/"));
46+
}
47+
48+
@Test
49+
public void normalizeWorkspaceRootDecoded() throws UnsupportedEncodingException {
50+
serverConfiguration.setWorkspaceRoot("file:/c:/foo bar/");
51+
assertThat(serverConfiguration.getWorkspaceRootURI().toFileString(), osEndsWith("c:/foo bar/"));
52+
53+
serverConfiguration.setWorkspaceRoot("c:/foo bar2/");
54+
assertThat(serverConfiguration.getWorkspaceRootURI().toFileString(), osEndsWith("c:/foo bar2/"));
4355
}
4456

4557
@Test

0 commit comments

Comments
 (0)