Skip to content

Commit e800ce0

Browse files
committed
fix: no handlong invalid url
1 parent b3ff041 commit e800ce0

File tree

4 files changed

+2
-12
lines changed

4 files changed

+2
-12
lines changed

src/mdImg.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@ export type MdImgOptions = {
55
alt?: string;
66
};
77
export const mdImg = ({ url, alt = "" }: MdImgOptions): string => {
8-
if (!/^https?:/.test(url)) {
9-
return alt;
10-
}
118
return `![${mdEscape(alt)}](${url})`;
129
};

src/mdLink.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ export type MdLinkOptions = {
66
title?: string;
77
};
88
export const mdLink = ({ text, url, title }: MdLinkOptions): string => {
9-
const isURL = /^https?:/.test(url);
10-
if (!isURL) {
11-
return text;
12-
}
139
if (title) {
1410
return `[${mdEscape(text)}](${url} "${mdEscape(title)}")`;
1511
}

test/mdImg.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import assert from "assert";
33

44
const properties: [actual: MdImgOptions, expected: string][] = [
55
[{ alt: "alt", url: "https://example.com" }, `![alt](https://example.com)`],
6-
[{ url: "https://example.com" }, `![](https://example.com)`],
7-
[{ url: "invalid url", alt: "alt" }, `alt`]
6+
[{ url: "https://example.com" }, `![](https://example.com)`]
87
];
98
describe("mdImg", function () {
109
properties.forEach((property) => {

test/mdLink.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ const properties: [actual: MdLinkOptions, expected: string][] = [
88
[
99
{ text: "<s>**strong**</s>", url: "https://example.com" },
1010
`[&lt;s&gt;\\*\\*strong\\*\\*&lt;\\/s&gt;](https://example.com)`
11-
],
12-
// illegal url
13-
[{ text: "text", url: "javascript:alert(1)" }, `text`]
11+
]
1412
];
1513
describe("mdLink", function () {
1614
properties.forEach((property) => {

0 commit comments

Comments
 (0)