Fix issues #28: InvalidCharacterError in getUrl when using non-Latin1
This commit is contained in:
@@ -44,7 +44,7 @@ export class ServerManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getUrl(): string {
|
getUrl(): string {
|
||||||
const encodedPath = btoa(this.projectDirectory);
|
const encodedPath = Buffer.from(this.projectDirectory).toString('base64');
|
||||||
return `http://${this.settings.hostname}:${this.settings.port}/${encodedPath}`;
|
return `http://${this.settings.hostname}:${this.settings.port}/${encodedPath}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ describe("ServerManager", () => {
|
|||||||
|
|
||||||
const url = currentManager.getUrl();
|
const url = currentManager.getUrl();
|
||||||
const expectedBase = `http://127.0.0.1:${port}`;
|
const expectedBase = `http://127.0.0.1:${port}`;
|
||||||
const expectedPath = btoa(PROJECT_DIR);
|
const expectedPath = Buffer.from(PROJECT_DIR).toString('base64');
|
||||||
|
|
||||||
expect(url).toBe(`${expectedBase}/${expectedPath}`);
|
expect(url).toBe(`${expectedBase}/${expectedPath}`);
|
||||||
});
|
});
|
||||||
@@ -285,4 +285,37 @@ describe("ServerManager", () => {
|
|||||||
expect(currentManager.getState()).toBe("stopped");
|
expect(currentManager.getState()).toBe("stopped");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Unicode path support", () => {
|
||||||
|
test("getUrl handles Chinese characters in project directory", () => {
|
||||||
|
const settings = createTestSettings(getNextPort());
|
||||||
|
const chinesePath = "C:/用户/Notes";
|
||||||
|
const manager = new ServerManager(settings, chinesePath);
|
||||||
|
|
||||||
|
const url = manager.getUrl();
|
||||||
|
|
||||||
|
expect(url).toContain("http://127.0.0.1:");
|
||||||
|
expect(url).toContain(Buffer.from(chinesePath).toString('base64'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getUrl handles Japanese characters in project directory", () => {
|
||||||
|
const settings = createTestSettings(getNextPort());
|
||||||
|
const japanesePath = "/home/ユーザー/ノート";
|
||||||
|
const manager = new ServerManager(settings, japanesePath);
|
||||||
|
|
||||||
|
const url = manager.getUrl();
|
||||||
|
|
||||||
|
expect(url).toContain(Buffer.from(japanesePath).toString('base64'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getUrl handles emoji in project directory", () => {
|
||||||
|
const settings = createTestSettings(getNextPort());
|
||||||
|
const emojiPath = "/home/user/📁Notes";
|
||||||
|
const manager = new ServerManager(settings, emojiPath);
|
||||||
|
|
||||||
|
const url = manager.getUrl();
|
||||||
|
|
||||||
|
expect(url).toContain(Buffer.from(emojiPath).toString('base64'));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user