From fec52a3989262e070dfdcd287b808b64b8ed0865 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Tue, 16 Jun 2020 06:04:04 -0700 Subject: [PATCH] escape app name to account for special characters in name (closes #1252) (#1268) Summary: App Names can contain special characters. Escape them (and unescape later) so that device ID strings don't break. Simpler is better - thanks to mweststrate for keeping me out of the rabbit hole ## Changelog Escape app name to account for special characters in name Pull Request resolved: https://github.com/facebook/flipper/pull/1268 Test Plan: Added test to test character escaping: `cd desktop && yarn test -- -i app/src/utils/__tests__/clientUtils.node.tsx` closes https://github.com/facebook/flipper/issues/1252 Reviewed By: passy Differential Revision: D22066263 Pulled By: jknoxville fbshipit-source-id: c820d055700ca6f55d35265528ce874eeb159216 --- .../src/utils/__tests__/clientUtils.node.tsx | 18 ++++++++++++++++++ desktop/app/src/utils/clientUtils.tsx | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) 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,