Pasting a link whose text/html label is a shortened form of its URL plants a `[` inside the URL
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 75/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- javascript
- Domínio
- frontend
Direção de pesquisa
Comece em src/paste-markdown-html.ts, por volta das linhas 83-90, onde convertToMarkdown localiza o rótulo HTML no texto sem formatação. Reproduza o caso da área de transferência descrito na issue, depois adicione os quatro testes de regressão descritos na correção proposta e execute a suíte de testes existente. Está concluído quando os rótulos de URL encurtadas forem substituídos corretamente sem corromper as URLs, enquanto os outros casos mantiverem o comportamento atual.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- JavaScript
- Estrelas
- 234
- Forks
- 47
- Merge médio
- 1d 12h
- PRs com merge (30d)
- 5
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de github/paste-markdown
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
github/paste-markdown#107 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 45/100
github/paste-markdown#104 ·
-
Examples page is broken Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
github/paste-markdown#100 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 48/100
github/paste-markdown#96 · 1 comentário ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 52/100
github/paste-markdown#94 ·
Todas as issues de github/paste-markdown
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
Daemon passes --experimental-wasm-jspi unconditionally on Node >= 24; Node 26 rejects the flag Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Automattic/studio#4908 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
sugarlabs/musicblocks#8847 ·