From 8ab8fb9e30683b288472272efc890a3a7493e0cf Mon Sep 17 00:00:00 2001 From: Jonathan Breedlove Date: Mon, 2 Dec 2024 10:41:47 -0800 Subject: [PATCH] Add handling for non standard paths on Windows --- .../eclipse/amazonq/views/ToolkitLoginWebview.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/views/ToolkitLoginWebview.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/views/ToolkitLoginWebview.java index 7108d3cb..381459a7 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/views/ToolkitLoginWebview.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/views/ToolkitLoginWebview.java @@ -4,8 +4,9 @@ package software.aws.toolkits.eclipse.amazonq.views; import java.io.IOException; -import java.net.URISyntaxException; import java.net.URL; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; @@ -112,8 +113,13 @@ public void onAuthStatusChanged(final AuthState authState) { private String getContent() { try { URL jsFile = PluginUtils.getResource("webview/build/assets/js/getStart.js"); - var jsParent = Paths.get(jsFile.toURI()).getParent(); - var jsDirectoryPath = Path.of(jsParent.toUri()).normalize().toString(); + String decodedPath = URLDecoder.decode(jsFile.getPath(), StandardCharsets.UTF_8); + + // Remove leading slash for Windows paths + decodedPath = decodedPath.replaceFirst("^/([A-Za-z]:)", "$1"); + + Path jsParent = Paths.get(decodedPath).getParent(); + String jsDirectoryPath = jsParent.normalize().toString(); webviewAssetServer = new WebviewAssetServer(); var result = webviewAssetServer.resolve(jsDirectoryPath); @@ -170,7 +176,7 @@ private String getContent() { """, loginJsPath, loginJsPath, loginJsPath, getWaitFunction(), isDarkTheme); - } catch (IOException | URISyntaxException e) { + } catch (IOException e) { return "Failed to load JS"; } }