Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] fix(mentions): encode user id in mentions URLs #4590

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ export default {
* @param {object} editor The Tiptap editor
*/
debugContent(editor) {
const proseMirrorMarkdown = this.$syncService.options.serialize(editor.state.doc)
const proseMirrorMarkdown = this.$syncService.serialize(editor.state.doc)
const markdownItHtml = markdownit.render(proseMirrorMarkdown)

logger.debug('markdown, serialized from editor state by prosemirror-markdown')
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/Mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default TipTapMention.extend({
tag: 'span[data-type="user"]',
getAttrs: element => {
return {
id: element.getAttribute('data-id'),
id: decodeURIComponent(element.getAttribute('data-id')),
label: element.innerText || element.textContent || element.getAttribute('data-label'),
}
},
Expand All @@ -36,7 +36,7 @@ export default TipTapMention.extend({

toMarkdown(state, node) {
state.write(' ')
state.write(`@[${node.attrs.label}](mention://user/${node.attrs.id})`)
state.write(`@[${node.attrs.label}](mention://user/${encodeURIComponent(node.attrs.id)})`)
state.write(' ')
},
})
1 change: 1 addition & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ describe('Markdown serializer from html', () => {

test('mentions', () => {
expect(markdownThroughEditorHtml('<span class="mention" data-label="username" data-type="user" data-id="id">username</span>')).toBe(' @[username](mention://user/id) ')
expect(markdownThroughEditorHtml('<span class="mention" data-label="whitespace user" data-type="user" data-id="whitespace user">whitespace user</span>')).toBe(' @[whitespace user](mention://user/whitespace%20user) ')
})
})

Expand Down
11 changes: 9 additions & 2 deletions src/tests/markdownit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ describe('markdownit', () => {
</ul>
<ul class="contains-task-list" data-bullet="*">
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-1" />task</li>
</ul>
`))
</ul>`
))
})

it('renders mentions of users with escaped whitespace', () => {
const rendered = markdownit.render('@[whitespace user](mention://user/whitespace%20user)')
expect(stripIndent(rendered)).toBe(stripIndent(`
<p><span class="mention" data-type="user" data-id="whitespace%20user">whitespace user</span></p>`
))
})

describe('callouts', () => {
Expand Down