Skip to content

Commit 5687f7e

Browse files
Stop encoding sidebar path
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 9d6d19c commit 5687f7e

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

cypress/e2e/mixins/oddname.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import { randHash } from '../../utils/'
2626
/**
2727
* Make a name aimed to break the viewer in case of escaping errors
2828
*
29-
* @param {String} realName
30-
* @returns {String} a name for the file to be uploaded as
29+
* @param {string} realName the file original name
30+
* @return {string} a name for the file to be uploaded as
3131
*/
3232
function naughtyFileName(realName) {
3333
const ext = realName.split('.').pop()
3434
return (
35-
'~⛰️ shot of a ${big} mountain`, '
35+
'~⛰️ shot of a $[big} mountain`, '
3636
+ "realy #1's "
3737
+ '" #_+="%2520%27%22%60%25%21%23 was this called '
3838
+ realName
@@ -50,7 +50,7 @@ Cypress.on('fail', (error, runnable) => {
5050
throw error // throw error to have test still fail
5151
})
5252

53-
export default function(file, type) {
53+
export default function(file, type, sidebar = false) {
5454
const placedName = naughtyFileName(file)
5555

5656
// We'll escape all the characters in the name to match it with css
@@ -62,7 +62,7 @@ export default function(file, type) {
6262
const folderName
6363
= 'Nextcloud "%27%22%60%25%21%23" >`⛰️<' + file + "><` e*'rocks!#?#%~"
6464

65-
describe(`Open ${file} in viewer with a naughty name`, function() {
65+
describe(`Open ${file} in viewer with a naughty name ${sidebar ? 'with sidebar' : ''}`, function() {
6666
before(function() {
6767
// fail fast
6868
if (failsLeft < 0) {
@@ -119,6 +119,24 @@ export default function(file, type) {
119119
it('See the menu icon and title on the viewer header', menuOk)
120120
it('Does not see navigation arrows', arrowsOK)
121121

122+
if (sidebar) {
123+
it('Open the sidebar', function() {
124+
// open the menu
125+
cy.get('body > .viewer .modal-header button.action-item__menutoggle').click()
126+
// open the sidebar
127+
cy.get('.action-button__icon.icon-menu-sidebar').click()
128+
cy.get('aside.app-sidebar').should('be.visible')
129+
// we hide the sidebar button if opened
130+
cy.get('.action-button__icon.icon-menu-sidebar').should('not.exist')
131+
// check the sidebar is opened for the correct file
132+
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__maintitle').should('contain', placedName)
133+
// check we do not have a preview
134+
cy.get('aside.app-sidebar .app-sidebar-header').should('have.class', 'app-sidebar-header--with-figure')
135+
cy.get('aside.app-sidebar .app-sidebar-header').should('have.class', 'app-sidebar-header--compact')
136+
cy.get('aside.app-sidebar .app-sidebar-header .app-sidebar-header__figure').should('have.attr', 'style').should('contain', 'core/filetypes')
137+
})
138+
}
139+
122140
it('Share the folder with a share link and access the share link', function() {
123141
cy.createLinkShare(folderName).then((token) => {
124142
cy.logout()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import runTest from '../mixins/oddname.js'
2+
3+
runTest('image.png', 'image/png', true)

src/mixins/PreviewUrl.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
*
2222
*/
23+
import { encodePath } from '@nextcloud/paths'
2324
import { generateUrl } from '@nextcloud/router'
2425
import { getToken, isPublic } from '../utils/davUtils.js'
25-
import { encodeFilePath, getDavPath } from '../utils/fileUtils.js'
26+
import { getDavPath } from '../utils/fileUtils.js'
2627

2728
export default {
2829
computed: {
@@ -73,7 +74,7 @@ export default {
7374
if (hasPreview) {
7475
// TODO: find a nicer standard way of doing this?
7576
if (isPublic()) {
76-
return generateUrl(`/apps/files_sharing/publicpreview/${getToken()}?file=${encodeFilePath(filename)}&${searchParams}`)
77+
return generateUrl(`/apps/files_sharing/publicpreview/${getToken()}?file=${encodePath(filename)}&${searchParams}`)
7778
}
7879
return generateUrl(`/core/preview?${searchParams}`)
7980
}

src/utils/fileUtils.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,13 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
import { dirname } from '@nextcloud/paths'
22+
import { dirname, encodePath } from '@nextcloud/paths'
2323
import { generateUrl } from '@nextcloud/router'
2424
import camelcase from 'camelcase'
2525

2626
import { getRootPath, getToken, getUserRoot, isPublic } from './davUtils.js'
2727
import { isNumber } from './numberUtil.js'
2828

29-
/**
30-
* Get an url encoded path
31-
*
32-
* @param {string} path the full path
33-
* @return {string} url encoded file path
34-
*/
35-
const encodeFilePath = function(path) {
36-
const pathSections = (path.startsWith('/') ? path : `/${path}`).split('/')
37-
let relativePath = ''
38-
pathSections.forEach((section) => {
39-
if (section !== '') {
40-
relativePath += '/' + encodeURIComponent(section)
41-
}
42-
})
43-
return relativePath
44-
}
45-
4629
/**
4730
* Extract dir and name from file path
4831
*
@@ -151,7 +134,7 @@ const getDavPath = function({ filename, basename, source = '' }) {
151134
if (filename.startsWith(prefixUser)) {
152135
filename = filename.slice(prefixUser.length)
153136
}
154-
return getRootPath() + encodeFilePath(filename)
137+
return getRootPath() + encodePath(filename)
155138
}
156139

157-
export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo, getDavPath }
140+
export { extractFilePaths, sortCompare, genFileInfo, getDavPath }

src/views/Viewer.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ export default {
284284
return this.Sidebar && this.Sidebar.file
285285
},
286286
sidebarOpenFilePath() {
287-
return this.currentFile?.davPath?.split(getUserRoot())[1]
287+
const relativePath = this.currentFile?.davPath?.split(getUserRoot())[1]
288+
return relativePath?.split('/')?.map(decodeURIComponent)?.join('/')
288289
},
289290
290291
/**

0 commit comments

Comments
 (0)