diff --git a/desktop/app/src/utils/__tests__/clientUtils.node.tsx b/desktop/app/src/utils/__tests__/clientUtils.node.tsx index 92492f7d2..f86b7bcea 100644 --- a/desktop/app/src/utils/__tests__/clientUtils.node.tsx +++ b/desktop/app/src/utils/__tests__/clientUtils.node.tsx @@ -48,3 +48,21 @@ test('client id deconstruction error logged', () => { }); expect(consoleErrorSpy).toHaveBeenCalledTimes(1); }); + +test('special characters in app name handled correctly', () => { + const consoleErrorSpy = jest.spyOn(global.console, 'error'); + + const testClient = { + app: '#myGreat#App&', + os: 'iOS', + device: 'iPhone Simulator', + device_id: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1', + }; + const clientId = buildClientId(testClient); + + const deconstructedClientId = deconstructClientId(clientId); + + expect(deconstructedClientId).toStrictEqual(testClient); + + expect(consoleErrorSpy).toHaveBeenCalledTimes(0); +}); diff --git a/desktop/app/src/utils/clientUtils.tsx b/desktop/app/src/utils/clientUtils.tsx index 82b7ab1f7..46e422a8f 100644 --- a/desktop/app/src/utils/clientUtils.tsx +++ b/desktop/app/src/utils/clientUtils.tsx @@ -72,14 +72,16 @@ export function buildClientId(clientInfo: { ); } } - return `${clientInfo.app}#${clientInfo.os}#${clientInfo.device}#${clientInfo.device_id}`; + const escapedName = escape(clientInfo.app); + return `${escapedName}#${clientInfo.os}#${clientInfo.device}#${clientInfo.device_id}`; } export function deconstructClientId(clientId: string): ClientIdConstituents { if (!clientId || clientId.split('#').length !== 4) { console.error(`Attempted to deconstruct invalid clientId: "${clientId}"`); } - const [app, os, device, device_id] = clientId.split('#'); + let [app, os, device, device_id] = clientId.split('#'); + app = unescape(app); return { app, os,