fix(vscode): insert embed flag before any url fragment
This commit is contained in:
parent
df2198739c
commit
6ec2d97587
|
|
@ -69,4 +69,10 @@ describe("appendEmbedQuery", () => {
|
|||
test("never percent-encodes the equals sign", () => {
|
||||
expect(appendEmbedQuery("http://127.0.0.1:1/")).not.toContain("%3D");
|
||||
});
|
||||
test("inserts before a fragment so location.search still sees the flag", () => {
|
||||
expect(appendEmbedQuery("http://127.0.0.1:1/#frag")).toBe("http://127.0.0.1:1/?embed=vscode#frag");
|
||||
expect(appendEmbedQuery("https://t.example/x?tkn=a#frag")).toBe(
|
||||
"https://t.example/x?tkn=a&embed=vscode#frag",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,7 +17,12 @@ export function originOf(url: string): string {
|
|||
* `EmbedHost::from_query` refuses by design. Tolerates a base that already
|
||||
* carries a query (e.g. tunnel tokens in remote scenarios). */
|
||||
export function appendEmbedQuery(base: string): string {
|
||||
return `${base}${base.includes("?") ? "&" : "?"}embed=vscode`;
|
||||
// Insert BEFORE any fragment — a plain tail-append after "#…" would land
|
||||
// the flag inside the fragment, where location.search never sees it.
|
||||
const hashAt = base.indexOf("#");
|
||||
const head = hashAt === -1 ? base : base.slice(0, hashAt);
|
||||
const fragment = hashAt === -1 ? "" : base.slice(hashAt);
|
||||
return `${head}${head.includes("?") ? "&" : "?"}embed=vscode${fragment}`;
|
||||
}
|
||||
|
||||
/** Phase 1: no iframe. On load it reports window.origin so the extension can
|
||||
|
|
|
|||
Loading…
Reference in a new issue