Pasting a link whose text/html label is a shortened form of its URL plants a `[` inside the URL
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu trong src/paste-markdown-html.ts, khoảng dòng 83-90, nơi convertToMarkdown xác định nhãn HTML trong văn bản thuần. Tái hiện trường hợp clipboard từ issue, sau đó thêm bốn bài kiểm thử hồi quy được mô tả trong bản sửa đề xuất và chạy bộ kiểm thử hiện có. Hoàn thành khi các nhãn URL rút gọn được thay thế chính xác mà không làm hỏng các URL, trong khi các trường hợp khác vẫn giữ nguyên hành vi hiện tại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens
When a clipboard carries a URL as text/plain and an anchor labelled with a shortened rendering of that URL as text/html, pasting into a GitHub comment box inserts the Markdown link syntax inside the URL:
text/plain: https://github.com/owner/repo/blob/main/a.js#L7
text/html: <a href="https://github.com/owner/repo/blob/main/a.js#L7">repo/blob/main/a.js#L7</a>
pasted: https://github.com/owner/[repo/blob/main/a.js#L7](https://github.com/owner/repo/blob/main/a.js#L7)
expected: [repo/blob/main/a.js#L7](https://github.com/owner/repo/blob/main/a.js#L7)
It renders as two links, one of them junk (https://github.com/owner/ on its own), and the comment has to be repaired by hand.
Reproduction
Run this in the console of any page with a GitHub comment box, press ⌘C/Ctrl+C, then paste into the box:
document.addEventListener('copy', event => {
const url = 'https://github.com/owner/repo/blob/main/a.js#L7'
event.clipboardData.setData('text/plain', url)
event.clipboardData.setData('text/html', `<a href="${url}">repo/blob/main/a.js#L7</a>`)
event.preventDefault()
}, {once: true})
Why it happens
convertToMarkdown starts from the plaintext flavour and splices [label](href) over the label at the offset where indexOf finds it:
https://github.com/github/paste-markdown/blob/main/src/paste-markdown-html.ts#L83-L90
That is correct for prose containing a link, where the plaintext is a flattening of the HTML. Here the plaintext is the URL and the label is a substring of it, so the label is found at offset 25 rather than 0 and the splice covers only the tail.
The same corruption happens when prose wraps the URL in punctuation — plaintext (https://github.com/owner/repo/blob/main/a.js#L7) yields (https://github.com/owner/[repo/…#L7](…)).
Who hits it
Any tool that writes a link to the clipboard as "URL as plaintext, shortened label as HTML" — macOS automation scripts (Hammerspoon/Alfred/Keyboard Maestro), clipboard managers, and "copy link" affordances that shorten the visible text. Labels containing a character the URL does not (repo#1234) are unaffected, because indexOf misses and the paste is left alone; every label that is a substring of its own URL is affected.
Proposed fix
#117 — replaces the whole URL when the label is a shortened rendering of it, declines rather than corrupting when the label sits inside a URL that is not its own href, and leaves every other case on the existing path. Four regression tests, all failing before the change.
- Ngôn ngữ chính
- JavaScript
- Star
- 234
- Fork
- 47
- Merge trung bình
- 1 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 5
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/paste-markdown
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
github/paste-markdown#107 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
github/paste-markdown#104 ·
-
Examples page is broken Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
github/paste-markdown#100 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
github/paste-markdown#96 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
github/paste-markdown#94 ·
Tất cả issue của github/paste-markdown
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
apache/cloudstack#14222 ·
-
Browser Waiting for: Product Owner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
getsentry/sentry-javascript#24577 · 1 bình luận ·
-
curation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
amponce/archive-movie-browser#186 ·
-
light
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
aemdemos/patients-stryker#253 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
clerk/javascript#9852 ·