Skip to content

Commit

Permalink
Merge pull request #4589 from nextcloud/backport/4588/stable27
Browse files Browse the repository at this point in the history
[stable27] fix(mentions): encode user id in mentions URLs
  • Loading branch information
mejo- committed Jul 27, 2023
2 parents 9dd4179 + 7ebe8d7 commit 5760a68
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/text-editors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-editors.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,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

0 comments on commit 5760a68

Please sign in to comment.