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

[stable31] fix: Properly show attachment extension #6701

Open
wants to merge 2 commits into
base: stable31
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion cypress/e2e/cardFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ describe('Card', function () {
cy.get('.file-picker__main [data-filename="welcome.txt"]', { timeout: 30000 }).should('be.visible')
.click()
cy.get('.dialog__actions button.button-vue--vue-primary').click()
cy.get('.attachment-list .basename').contains('welcome.txt')
cy.get('.attachment-list .filename').contains('welcome')
cy.get('.attachment-list .filename .extension').contains('txt')
})

it('Shows the modal with the editor', () => {
Expand Down
14 changes: 12 additions & 2 deletions src/components/card/AttachmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<div class="details">
<a>
<div class="filename">
<span class="basename">{{ attachment.name }}</span>
<span>{{ attachmentBasename(attachment) }}</span>
<span class="extension">.{{ attachmentExtension(attachment) }}</span>
</div>
<progress :value="attachment.progress" max="100" />
</a>
Expand All @@ -41,7 +42,8 @@
<div class="details">
<a :href="internalLink(attachment)" @click.prevent="showViewer(attachment)">
<div class="filename">
<span class="basename">{{ attachment.data }}</span>
<span>{{ attachmentBasename(attachment) }}</span>
<span class="extension">.{{ attachmentExtension(attachment) }}</span>
</div>
<div v-if="attachment.deletedAt === 0">
<span class="filesize">{{ formattedFileSize(attachment.extendedData.filesize) }}</span>
Expand Down Expand Up @@ -183,6 +185,14 @@ export default {
return t('deck', 'Drop your files to upload')
}
},
attachmentBasename() {
return (attachment) => attachment?.extendedData?.info.filename
?? (attachment?.name ?? attachment.data).replace(/\.[^/.]+$/, '')
},
attachmentExtension() {
return (attachment) => attachment?.extendedData?.info?.extension
?? (attachment?.name ?? attachment.data).split('.').pop()
},
},
watch: {
cardId: {
Expand Down
7 changes: 5 additions & 2 deletions src/components/card/Description.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
id="description-preview"
dir="auto"
@click="clickedPreview"
v-html="renderedDescription" />

Check warning on line 43 in src/components/card/Description.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'v-html' directive can lead to XSS attack
<p v-else-if="!descriptionEditing" class="placeholder" @click="showEditor()">
{{ t('deck', 'Write a description …') }}
</p>
Expand Down Expand Up @@ -239,15 +239,18 @@
},
addAttachment(attachment) {
const asImage = (attachment.type === 'file' && attachment.extendedData.hasPreview) || attachment.extendedData.mimetype.includes('image')
// We need to strip those as text does not support rtl yet, so we cannot insert them separately
const stripRTLO = (text) => text.replaceAll('\u202e', '')
const fileName = stripRTLO(attachment.extendedData.info.filename) + '.' + stripRTLO(attachment.extendedData.info.extension)
if (this.editor) {
this.editor.insertAtCursor(
asImage
? `<a href="${this.attachmentPreview(attachment)}"><img src="${this.attachmentPreview(attachment)}" alt="${attachment.data}" /></a>`
: `<a href="${this.attachmentPreview(attachment)}">${attachment.data}</a>`,
: `<a href="${this.attachmentPreview(attachment)}">${fileName}</a>`,
)
return
} else {
const attachmentString = (asImage ? '!' : '') + '[📎 ' + attachment.data + '](' + this.attachmentPreview(attachment) + ')'
const attachmentString = (asImage ? '!' : '') + '[📎 ' + fileName + '](' + this.attachmentPreview(attachment) + ')'
const descString = this.$refs.markdownEditor.easymde.value()
const newContent = descString + '\n' + attachmentString
this.$refs.markdownEditor.easymde.value(newContent)
Expand Down
Loading