mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-31 21:48:19 +00:00
fix: correct full url when using sub-path (#38712)
fix #38708 --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import {svg} from '../svg.ts';
|
||||
import {createTippy} from '../modules/tippy.ts';
|
||||
import {toAbsoluteUrl} from '../utils.ts';
|
||||
import {addDelegatedEventListener} from '../utils/dom.ts';
|
||||
|
||||
function changeHash(hash: string) {
|
||||
@@ -24,7 +23,7 @@ function selectRange(range: string): Element | null {
|
||||
if (!refInNewIssue) return;
|
||||
const urlIssueNew = refInNewIssue.getAttribute('data-url-issue-new');
|
||||
const urlParamBodyLink = refInNewIssue.getAttribute('data-url-param-body-link')!;
|
||||
const issueContent = `${toAbsoluteUrl(urlParamBodyLink)}#${anchor}`; // the default content for issue body
|
||||
const issueContent = `${urlParamBodyLink}#${anchor}`; // the default content for issue body
|
||||
refInNewIssue.setAttribute('href', `${urlIssueNew}?body=${encodeURIComponent(issueContent)}`);
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
} from '../utils/dom.ts';
|
||||
import {setFileFolding} from './file-fold.ts';
|
||||
import {ComboMarkdownEditor, getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts';
|
||||
import {toAbsoluteUrl} from '../utils.ts';
|
||||
import {GET, POST} from '../modules/fetch.ts';
|
||||
import {showErrorToast} from '../modules/toast.ts';
|
||||
import {initRepoIssueSidebar} from './repo-issue-sidebar.ts';
|
||||
@@ -329,7 +328,7 @@ export function initRepoIssueReferenceIssue() {
|
||||
const target = el.getAttribute('data-target');
|
||||
const content = document.querySelector(`#${target}`)?.textContent ?? '';
|
||||
const poster = el.getAttribute('data-poster-username');
|
||||
const reference = toAbsoluteUrl(el.getAttribute('data-reference')!);
|
||||
const reference = el.getAttribute('data-reference')!;
|
||||
const modalSelector = el.getAttribute('data-modal')!;
|
||||
const modal = document.querySelector(modalSelector)!;
|
||||
const textarea = modal.querySelector<HTMLTextAreaElement>('textarea[name="content"]')!;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
dirname, basename, extname, formatBytes, isObject, stripTags, parseIssueHref,
|
||||
translateMonth, translateDay, blobToDataURI,
|
||||
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64, isImageFile, isVideoFile, parseRepoOwnerPathInfo,
|
||||
encodeURLEncodedBase64, decodeURLEncodedBase64, isImageFile, isVideoFile, parseRepoOwnerPathInfo,
|
||||
} from './utils.ts';
|
||||
|
||||
test('dirname', () => {
|
||||
@@ -88,16 +88,6 @@ test('blobToDataURI', async () => {
|
||||
expect(await blobToDataURI(blob)).toEqual('data:application/json;base64,eyJ0ZXN0Ijp0cnVlfQ==');
|
||||
});
|
||||
|
||||
test('toAbsoluteUrl', () => {
|
||||
expect(toAbsoluteUrl('//host/dir')).toEqual('http://host/dir');
|
||||
expect(toAbsoluteUrl('https://host/dir')).toEqual('https://host/dir');
|
||||
|
||||
expect(toAbsoluteUrl('')).toEqual('http://localhost:3000');
|
||||
expect(toAbsoluteUrl('/user/repo')).toEqual('http://localhost:3000/user/repo');
|
||||
|
||||
expect(() => toAbsoluteUrl('path')).toThrow('unsupported');
|
||||
});
|
||||
|
||||
test('encodeURLEncodedBase64, decodeURLEncodedBase64', () => {
|
||||
const encoder = new TextEncoder();
|
||||
const uint8array = encoder.encode.bind(encoder);
|
||||
|
||||
@@ -142,19 +142,6 @@ export function convertImage(blob: Blob, mime: string): Promise<Blob> {
|
||||
});
|
||||
}
|
||||
|
||||
export function toAbsoluteUrl(url: string): string {
|
||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||
return url;
|
||||
}
|
||||
if (url.startsWith('//')) {
|
||||
return `${window.location.protocol}${url}`; // it's also a somewhat absolute URL (with the current scheme)
|
||||
}
|
||||
if (url && !url.startsWith('/')) {
|
||||
throw new Error('unsupported url, it should either start with / or http(s)://');
|
||||
}
|
||||
return `${window.location.origin}${url}`;
|
||||
}
|
||||
|
||||
/** Encode an Uint8Array into a URLEncoded base64 string. */
|
||||
export function encodeURLEncodedBase64(uint8Array: Uint8Array): string {
|
||||
return btoa(Array.from(uint8Array, (byte) => String.fromCharCode(byte)).join(''))
|
||||
|
||||
Reference in New Issue
Block a user