Skip to content

Commit d41be5f

Browse files
Copilotcyanzhong
andauthored
Narrow relative link handling to only ../ paths
Per maintainer feedback, restrict the click interception to links starting with "../" only. Remove the now-unnecessary isRelativePath() utility and its test file. Agent-Logs-Url: https://github.com/MarkEdit-app/MarkEdit-preview/sessions/bf2367cc-cfbf-4aab-8991-df30b8f2a973 Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
1 parent 68b73d1 commit d41be5f

3 files changed

Lines changed: 2 additions & 72 deletions

File tree

src/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,6 @@ export function joinPaths(path1: string, path2: string) {
9090
return path1 + '/' + path2;
9191
}
9292

93-
export function isRelativePath(href: string) {
94-
// Anchor links
95-
if (href.startsWith('#')) {
96-
return false;
97-
}
98-
99-
// Absolute URLs (http:, https:, mailto:, data:, etc.) or protocol-relative URLs
100-
if (/^([a-z][a-z0-9+.-]*:|\/\/)/i.test(href)) {
101-
return false;
102-
}
103-
104-
return true;
105-
}
106-
10793
export function stripQuotes(input: string) {
10894
if ((input.startsWith('"') && input.endsWith('"')) || (input.startsWith("'") && input.endsWith("'"))) {
10995
return input.slice(1, -1);

src/view.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MarkEdit } from 'markedit-api';
2-
import { appendStyle, getFileExtension, getFileName, isRelativePath, joinPaths, selectFullRange } from './utils';
2+
import { appendStyle, getFileExtension, getFileName, joinPaths, selectFullRange } from './utils';
33
import { renderMarkdown, renderMermaid, renderKatex, handlePostRender, applyStyles } from './render';
44
import { replaceImageURLs } from './image';
55
import { hidePreviewButtons, previewModes } from './settings';
@@ -77,7 +77,7 @@ export function setUp() {
7777

7878
// Use getAttribute to get the raw href, not the resolved absolute URL
7979
const href = anchor.getAttribute('href');
80-
if (href === null || href === '' || !isRelativePath(href)) {
80+
if (!href?.startsWith('../')) {
8181
return;
8282
}
8383

tests/utils.test.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)