Skip to content

Commit

Permalink
Merge pull request #6254 from nextcloud/backport/6253/stable4.7
Browse files Browse the repository at this point in the history
[stable4.7] fix: make call token extraction more robust
  • Loading branch information
miaulalala authored Aug 12, 2024
2 parents d51f09e + 7ddd9aa commit 1ed2497
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/services/talkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function updateTalkParticipants(eventComponent) {
logger.debug('Event\'s conference/location is from another host', url)
return
}
const token = url.match(/\/call\/([a-z0-9]*)$/)[1]
const token = extractCallTokenFromUrl(url)
if (!token) {
logger.debug('URL ' + url + ' contains no call token')
return
Expand Down Expand Up @@ -148,3 +148,13 @@ export function doesContainTalkLink(text) {
function generateURLForToken(token = '') {
return window.location.protocol + '//' + window.location.host + generateUrl('/call/' + token)
}

/**
* Extract a spreed call token from the given URL
*
* @param {string} callUrl URL of the spreed call
* @return {string|undefined} Matched token or undefined if URL is invalid
*/
export function extractCallTokenFromUrl(callUrl) {
return callUrl.match(/\/call\/([a-z0-9]*)(\/|#.*)?$/)?.[1] ?? undefined
}
21 changes: 21 additions & 0 deletions tests/javascript/unit/services/talkService.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { extractCallTokenFromUrl } from '../../../../src/services/talkService'

describe('services/talk test suite', () => {
test.each([
['https://foo.bar/call/123abc456', '123abc456'],
['https://foo.bar/call/123abc456/', '123abc456'],
['https://foo.bar/call/123abc456/baz', undefined],
['https://foo.bar/call/123abc456#', '123abc456'],
['https://foo.bar/call/123abc456#/', '123abc456'],
['https://foo.bar/call/123abc456#message_3074226', '123abc456'],
['https://foo.bar/baz', undefined],
['https://foo.bar/baz/bar', undefined],
])('should extract a token from call url %s', (url, expected) => {
expect(extractCallTokenFromUrl(url)).toBe(expected)
})
})

0 comments on commit 1ed2497

Please sign in to comment.