Merge pull request #830 from tdurieux/fix/legacy-hashbang-repository-urls

fix: restore legacy hashbang repository links
This commit is contained in:
Thomas Durieux
2026-09-14 16:37:19 +02:00
committed by GitHub
3 changed files with 31 additions and 0 deletions
+1
View File
@@ -28,4 +28,5 @@ jobs:
node-version: 22 node-version: 22
cache: npm cache: npm
- run: npm ci - run: npm ci
- run: npm run build:ui
- run: npm test - run: npm test
+5
View File
@@ -30,6 +30,11 @@ export function safeUrl(value) {
} }
export function mountApplication(target = "#app", options = {}) { export function mountApplication(target = "#app", options = {}) {
// AngularJS links stored the repository route in the fragment. Normalize it
// before web history reads the URL, replacing the entry so Back still works.
if (!options.history && window.location.pathname === "/" && /^#!\/r\/[^/?#]+/.test(window.location.hash)) {
window.history.replaceState(window.history.state, "", window.location.hash.slice(2));
}
const events = new Map(); const events = new Map();
const http = createHttp(options.fetch); const http = createHttp(options.fetch);
let root; let root;
+25
View File
@@ -75,6 +75,31 @@ describe("Vue 3 UI", function () {
let ui; let ui;
afterEach(() => ui?.close()); afterEach(() => ui?.close());
for (const path of [
"/r/submission-artifact-604F/",
"/r/submission-artifact-604F",
"/r/submission-artifact-604F/src/hello%20world.js?raw=1&value=a%2Fb#L12",
]) {
it(`opens a legacy hashbang repository link at ${path}`, async function () {
ui = await browser("/#!" + path);
expect(ui.app.router.currentRoute.value.fullPath).to.equal(path);
expect(ui.app.router.currentRoute.value.params.repoId).to.equal("submission-artifact-604F");
expect(ui.window.location.href).to.equal("http://localhost" + path);
expect(ui.window.history.length).to.equal(1);
expect(ui.requests.some(request => request.url.pathname.startsWith("/api/repo/submission-artifact-604F/"))).to.equal(true);
expect(ui.errors).to.deep.equal([]);
});
}
for (const path of ["/r/test/#L12", "/#ordinary-anchor", "/#!//example.com/r/test/"]) {
it(`leaves a nonlegacy URL unchanged: ${path}`, async function () {
ui = await browser(path);
expect(ui.window.location.href).to.equal("http://localhost" + path);
expect(ui.app.router.currentRoute.value.fullPath).to.equal(path);
expect(ui.errors).to.deep.equal([]);
});
}
it("renders every public and administrative route", async function () { it("renders every public and administrative route", async function () {
ui = await browser(); ui = await browser();
for (const route of ["/faq", "/anonymize", "/gist-anonymize", "/pull-request-anonymize", "/status/test", "/404", "/r/test/", "/repository/test/", "/pr/test/", "/gist/test/"]) { for (const route of ["/faq", "/anonymize", "/gist-anonymize", "/pull-request-anonymize", "/status/test", "/404", "/r/test/", "/repository/test/", "/pr/test/", "/gist/test/"]) {