Skip to content

Commit

Permalink
Only open direct link files if link points to Files app
Browse files Browse the repository at this point in the history
Until now, we always opened direct link files when a link contained
a `fileId` query parameter. This breaks e.g. links to pages from the
Collectives app, which contain `fileId` parameters as well.

Limit opening direct file link to links that point to the Files app.

Fixes: #3857

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- authored and backportbot-nextcloud[bot] committed Mar 6, 2023
1 parent d79cdaf commit 6078598
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions cypress/e2e/nodes/Links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ describe('test link marks', function() {
})

describe('autolink', function() {
it('with protocol', () => {
it('with protocol to files app and fileId', () => {
cy.getFile(fileName)
.then($el => {
const id = $el.data('id')

const link = `${Cypress.env('baseUrl')}/file-name?fileId=${id}`
const link = `${Cypress.env('baseUrl')}/apps/files/file-name?fileId=${id}`
cy.clearContent()
.type(`${link}{enter}`)

Expand All @@ -63,6 +63,25 @@ describe('test link marks', function() {
})
})

it('with protocol and fileId', () => {
cy.getFile(fileName)
.then($el => {
const id = $el.data('id')

const link = `${Cypress.env('baseUrl')}/file-name?fileId=${id}`
cy.clearContent()
.type(`${link}{enter}`)

cy.getContent()
.find(`a[href*="${Cypress.env('baseUrl')}"]`)
.click({ force: true })

cy.get('@winOpen')
.should('have.been.calledOnce')
.should('have.been.calledWithMatch', new RegExp(`${Cypress.env('baseUrl')}/file-name\\?fileId=${id}$`))
})
})

it('without protocol', () => {
cy.clearContent()
.type('google.com{enter}')
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const openLink = function(event, _attrs) {
OCA.Viewer.open({ path })
return
}
if (query?.fileId) {
if (htmlHref.match(/apps\/files\//) && query?.fileId) {
// open the direct file link
window.open(generateUrl(`/f/${query.fileId}`), '_self')
return
Expand Down

0 comments on commit 6078598

Please sign in to comment.