Skip to content

Commit 2add0b2

Browse files
author
Akos Kitta
committed
fix: force workaround logic run when # in the path
Signed-off-by: Akos Kitta <[email protected]>
1 parent 8aaf65e commit 2add0b2

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

arduino-ide-extension/src/node/theia/plugin-ext/plugin-deployer.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ export class LocalDirectoryPluginDeployerResolverWithFallback extends LocalDirec
1818
override async resolve(
1919
pluginResolverContext: PluginDeployerResolverContext
2020
): Promise<void> {
21-
let localPath = await this.originalResolveLocalPluginPath(
22-
pluginResolverContext,
23-
this.supportedScheme
24-
);
25-
// If local plugins folder was not resoled, fallback to the hack.
26-
if (!localPath) {
27-
localPath = await resolveLocalPluginPath(
21+
const origin = pluginResolverContext.getOriginId();
22+
// The original implementation must not run when there is a hash in the path. Otherwise, it can resolve an undesired directory.
23+
// Consider app under c:\Users\username\Desktop\# here is my app\
24+
// Then the flawed logic will incorrectly find c:\Users\username\Desktop location after stripping the rest of the path after the hash.
25+
// The implementation which provides a workaround for the hash in the path assumes that the original Theia logic is correct, when no hash present in the URI path.
26+
let localPath: string | null;
27+
if (origin.includes('#')) {
28+
localPath = await resolveLocalPluginPathFallback(
29+
pluginResolverContext,
30+
this.supportedScheme
31+
);
32+
} else {
33+
localPath = await this.originalResolveLocalPluginPath(
2834
pluginResolverContext,
2935
this.supportedScheme
3036
);
@@ -49,14 +55,14 @@ export class LocalDirectoryPluginDeployerResolverWithFallback extends LocalDirec
4955
}
5056
}
5157

52-
async function resolveLocalPluginPath(
58+
async function resolveLocalPluginPathFallback(
5359
context: PluginDeployerResolverContext,
5460
scheme: string
5561
): Promise<string | null> {
56-
const origin = context.getOriginId();
57-
const uri = new URI(origin);
62+
const uri = new URI(context.getOriginId());
5863
if (uri.scheme === scheme) {
59-
let fsPath = origin.substring(`${scheme}:`.length);
64+
const unencodedRawUri = uri.toString(true);
65+
let fsPath = unencodedRawUri.substring(`${scheme}:`.length);
6066
if (!isAbsolute(fsPath)) {
6167
fsPath = resolve(process.cwd(), fsPath);
6268
}

0 commit comments

Comments
 (0)