Skip to content

Commit c4ea019

Browse files
authored
Merge pull request #6701 from nextcloud/backport/6671/stable31
[stable31] fix: Properly show attachment extension
2 parents 6a19934 + 2473117 commit c4ea019

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

cypress/e2e/cardFeatures.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ describe('Card', function () {
187187
cy.get('.file-picker__main [data-filename="welcome.txt"]', { timeout: 30000 }).should('be.visible')
188188
.click()
189189
cy.get('.dialog__actions button.button-vue--vue-primary').click()
190-
cy.get('.attachment-list .basename').contains('welcome.txt')
190+
cy.get('.attachment-list .filename').contains('welcome')
191+
cy.get('.attachment-list .filename .extension').contains('txt')
191192
})
192193

193194
it('Shows the modal with the editor', () => {

src/components/card/AttachmentList.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<div class="details">
2525
<a>
2626
<div class="filename">
27-
<span class="basename">{{ attachment.name }}</span>
27+
<span>{{ attachmentBasename(attachment) }}</span>
28+
<span class="extension">.{{ attachmentExtension(attachment) }}</span>
2829
</div>
2930
<progress :value="attachment.progress" max="100" />
3031
</a>
@@ -41,7 +42,8 @@
4142
<div class="details">
4243
<a :href="internalLink(attachment)" @click.prevent="showViewer(attachment)">
4344
<div class="filename">
44-
<span class="basename">{{ attachment.data }}</span>
45+
<span>{{ attachmentBasename(attachment) }}</span>
46+
<span class="extension">.{{ attachmentExtension(attachment) }}</span>
4547
</div>
4648
<div v-if="attachment.deletedAt === 0">
4749
<span class="filesize">{{ formattedFileSize(attachment.extendedData.filesize) }}</span>
@@ -183,6 +185,14 @@ export default {
183185
return t('deck', 'Drop your files to upload')
184186
}
185187
},
188+
attachmentBasename() {
189+
return (attachment) => attachment?.extendedData?.info.filename
190+
?? (attachment?.name ?? attachment.data).replace(/\.[^/.]+$/, '')
191+
},
192+
attachmentExtension() {
193+
return (attachment) => attachment?.extendedData?.info?.extension
194+
?? (attachment?.name ?? attachment.data).split('.').pop()
195+
},
186196
},
187197
watch: {
188198
cardId: {

src/components/card/Description.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,18 @@ export default {
239239
},
240240
addAttachment(attachment) {
241241
const asImage = (attachment.type === 'file' && attachment.extendedData.hasPreview) || attachment.extendedData.mimetype.includes('image')
242+
// We need to strip those as text does not support rtl yet, so we cannot insert them separately
243+
const stripRTLO = (text) => text.replaceAll('\u202e', '')
244+
const fileName = stripRTLO(attachment.extendedData.info.filename) + '.' + stripRTLO(attachment.extendedData.info.extension)
242245
if (this.editor) {
243246
this.editor.insertAtCursor(
244247
asImage
245248
? `<a href="${this.attachmentPreview(attachment)}"><img src="${this.attachmentPreview(attachment)}" alt="${attachment.data}" /></a>`
246-
: `<a href="${this.attachmentPreview(attachment)}">${attachment.data}</a>`,
249+
: `<a href="${this.attachmentPreview(attachment)}">${fileName}</a>`,
247250
)
248251
return
249252
} else {
250-
const attachmentString = (asImage ? '!' : '') + '[📎 ' + attachment.data + '](' + this.attachmentPreview(attachment) + ')'
253+
const attachmentString = (asImage ? '!' : '') + '[📎 ' + fileName + '](' + this.attachmentPreview(attachment) + ')'
251254
const descString = this.$refs.markdownEditor.easymde.value()
252255
const newContent = descString + '\n' + attachmentString
253256
this.$refs.markdownEditor.easymde.value(newContent)

0 commit comments

Comments
 (0)