match the appSubUrl shape Gitea actually emits
The regex expected JSON — "appSubUrl":"…" — and Gitea emits a JavaScript object literal: unquoted key, single quotes, `appSubUrl: ''`. So the single highest-value rewrite in this file silently did nothing on every real page, while every attribute around it rewrote perfectly. The test used the shape I guessed rather than the shape Gitea produces, which is why it passed. Now covers both, with the real form taken verbatim from a live response, and asserts the quote style survives — swapping it would stop the literal parsing.
This commit is contained in:
@@ -40,6 +40,17 @@ describe('appSubUrl — the line that makes Gitea correct itself', () => {
|
||||
test('an existing subpath is replaced, not appended to', () => {
|
||||
expect(rewriteAppSubUrl('{"appSubUrl":"/git"}', BASE)).toBe(`{"appSubUrl":"${BASE}"}`);
|
||||
});
|
||||
|
||||
// The shape Gitea ACTUALLY emits — a JavaScript object literal, unquoted key, single quotes. The first
|
||||
// version of this only matched the JSON form, so it silently did nothing on every real page while the
|
||||
// attributes around it rewrote perfectly. Taken verbatim from a live response.
|
||||
test('the JS object-literal form Gitea really emits', () => {
|
||||
const real = "window.config = {\n appUrl: 'https://gitea.officer.dev/',\n appSubUrl: '',\n};";
|
||||
const out = rewriteAppSubUrl(real, BASE);
|
||||
expect(out).toContain(`appSubUrl: '${BASE}'`);
|
||||
// The quote style is preserved, or the literal stops parsing.
|
||||
expect(out).not.toContain(`appSubUrl: "${BASE}"`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('absolute URLs built from ROOT_URL', () => {
|
||||
|
||||
Reference in New Issue
Block a user