mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(webview): resolve a relative base against the document directory
rebaseRelativeBase resolved a relative <base> against the proxy root, so a document served from a subdirectory of its dashboard (for example /webview/<cap>/app/page.html with <base href="./">) pointed at /webview/<cap>/ and loaded its assets one level too high. Pass the request's wildcard path into rewriteHtml and resolve the base against the document URL, which keeps the proxy root for the landing page.
This commit is contained in:
1 parent
238853f96a
commit
cc413afdd1
6 files changed
+66
-9
No files matched your search
@@ -395,6 +395,19 @@ describe('rewriteHtml', () => {
|
||||
expect(out).toContain(`<base target="_blank" href="${PREFIX}sub/">`);
|
||||
});
|
||||
|
||||
// A document served from a subdirectory resolves its relative base against
|
||||
// ITS directory, not the proxy root: `/webview/<cap>/app/page.html` with
|
||||
// `<base href="./">` must point at `/webview/<cap>/app/`.
|
||||
it("resolves a relative <base> against the document's own directory", () => {
|
||||
const out = rewriteHtml('<html><head><base href="./"></head></html>', CAP, '', 'app/page.html');
|
||||
expect(out).toContain(`<base href="${PREFIX}app/">`);
|
||||
});
|
||||
|
||||
it('resolves a ../ base from the document directory', () => {
|
||||
const out = rewriteHtml('<html><head><base href="../assets/"></head></html>', CAP, '', 'app/sub/page.html');
|
||||
expect(out).toContain(`<base href="${PREFIX}app/assets/">`);
|
||||
});
|
||||
|
||||
it('leaves a cross-origin <base> exactly as the author wrote it', () => {
|
||||
const out = rewriteHtml('<html><head><base href="https://cdn.example/x/"></head></html>', CAP);
|
||||
expect(out).toContain('<base href="https://cdn.example/x/">');
|
||||
|
||||
Reference in new issue
Block a user