Skip to content

Commit ea51365

Browse files
susnuxskjnldsv
authored andcommitted
fix: Ensure displayname is a string
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 8d00d46 commit ea51365

File tree

95 files changed

+284
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+284
-193
lines changed

apps/files/src/components/FileEntryMixin.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,24 @@ export default defineComponent({
8888
* Either the nodes filename or a custom display name (e.g. for shares)
8989
*/
9090
displayName() {
91-
const ext = this.extension
92-
const name = String(this.source.attributes.displayname || this.source.basename)
91+
return this.source.displayname
92+
},
93+
/**
94+
* The display name without extension
95+
*/
96+
basename() {
97+
if (this.extension === '') {
98+
return this.displayName
99+
}
100+
return this.displayName.slice(0, 0 - this.extension.length)
101+
},
102+
/**
103+
* The extension of the file
104+
*/
105+
extension() {
106+
if (this.source.type === FileType.Folder) {
107+
return ''
108+
}
93109

94110
return extname(this.displayName)
95111
},

apps/files/src/services/Files.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ export const resultToNode = function(node: FileStat): File | Folder {
5454
? hashCode(source)
5555
: props?.fileid as number || 0
5656

57+
// TODO remove this hack with nextcloud-files v3.7
58+
// just needed because of a bug in the webdav client
59+
if (node.props?.displayname !== undefined) {
60+
node.props.displayname = String(node.props.displayname)
61+
}
62+
5763
const nodeData = {
5864
id,
5965
source,

apps/files/src/views/FilesList.vue

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ import type { UserConfig } from '../types.ts'
126126
import { getCapabilities } from '@nextcloud/capabilities'
127127
import { showError } from '@nextcloud/dialogs'
128128
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
129-
import { Folder, Node, Permission } from '@nextcloud/files'
129+
import { Folder, Node, Permission, sortNodes } from '@nextcloud/files'
130130
import { loadState } from '@nextcloud/initial-state'
131131
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
132132
import { ShareType } from '@nextcloud/sharing'
@@ -272,40 +272,6 @@ export default defineComponent({
272272
return this.filesStore.getNode(source) as Folder
273273
},
274274
275-
/**
276-
* Directory content sorting parameters
277-
* Provided by an extra computed property for caching
278-
*/
279-
sortingParameters() {
280-
const identifiers = [
281-
// 1: Sort favorites first if enabled
282-
...(this.userConfig.sort_favorites_first ? [v => v.attributes?.favorite !== 1] : []),
283-
// 2: Sort folders first if sorting by name
284-
...(this.userConfig.sort_folders_first ? [v => v.type !== 'folder'] : []),
285-
// 3: Use sorting mode if NOT basename (to be able to use displayName too)
286-
...(this.sortingMode !== 'basename' ? [v => v[this.sortingMode]] : []),
287-
// 4: Use displayname if available, fallback to name
288-
v => v.attributes?.displayname || v.basename,
289-
// 5: Finally, use basename if all previous sorting methods failed
290-
v => v.basename,
291-
]
292-
const orders = [
293-
// (for 1): always sort favorites before normal files
294-
...(this.userConfig.sort_favorites_first ? ['asc'] : []),
295-
// (for 2): always sort folders before files
296-
...(this.userConfig.sort_folders_first ? ['asc'] : []),
297-
// (for 3): Reverse if sorting by mtime as mtime higher means edited more recent -> lower
298-
...(this.sortingMode === 'mtime' ? [this.isAscSorting ? 'desc' : 'asc'] : []),
299-
// (also for 3 so make sure not to conflict with 2 and 3)
300-
...(this.sortingMode !== 'mtime' && this.sortingMode !== 'basename' ? [this.isAscSorting ? 'asc' : 'desc'] : []),
301-
// for 4: use configured sorting direction
302-
this.isAscSorting ? 'asc' : 'desc',
303-
// for 5: use configured sorting direction
304-
this.isAscSorting ? 'asc' : 'desc',
305-
]
306-
return [identifiers, orders] as const
307-
},
308-
309275
/**
310276
* The current directory contents.
311277
*/

cypress/e2e/files/files_sorting.cy.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ describe('Files: Sorting the file list', { testIsolation: true }, () => {
5858
})
5959
})
6060

61+
/**
62+
* Regression test of https://github.com/nextcloud/server/issues/45829
63+
*/
64+
it('Filesnames with numbers are sorted by name ascending by default', () => {
65+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/name.txt')
66+
.uploadContent(currentUser, new Blob(), 'text/plain', '/name_03.txt')
67+
.uploadContent(currentUser, new Blob(), 'text/plain', '/name_02.txt')
68+
.uploadContent(currentUser, new Blob(), 'text/plain', '/name_01.txt')
69+
cy.login(currentUser)
70+
cy.visit('/apps/files')
71+
72+
cy.get('[data-cy-files-list-row]').each(($row, index) => {
73+
switch (index) {
74+
case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('name.txt')
75+
break
76+
case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_01.txt')
77+
break
78+
case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_02.txt')
79+
break
80+
case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_03.txt')
81+
break
82+
}
83+
})
84+
})
85+
6186
it('Can sort by size', () => {
6287
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 tiny.txt')
6388
.uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z big.txt')

dist/4065-4065.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/4065-4065.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/6075-6075.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/6075-6075.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/8985-8985.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/8985-8985.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)