From 60fd278a346d2e65c27cf3f963899a06b0a79e76 Mon Sep 17 00:00:00 2001 From: BacLuc Date: Sat, 16 Nov 2024 17:38:07 +0100 Subject: [PATCH] campShortTitle.js: fix error for non string camp.shortTitle Fixes #6363 --- common/helpers/__tests__/campShortTitle.spec.js | 9 +++++++++ common/helpers/campShortTitle.js | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/helpers/__tests__/campShortTitle.spec.js b/common/helpers/__tests__/campShortTitle.spec.js index f992d457eb..ed452cf03f 100644 --- a/common/helpers/__tests__/campShortTitle.spec.js +++ b/common/helpers/__tests__/campShortTitle.spec.js @@ -37,6 +37,15 @@ describe('campShortTitle', () => { [{ shortTitle: undefined, title: null }, ''], [{ shortTitle: '0', title: 'Sola24' }, '0'], [{ shortTitle: '', title: 'Sola24' }, 'SoLa24'], + + //error cases + [{ shortTitle: 0, title: 'Sola24' }, '0'], + [{ shortTitle: false, title: 'Sola24' }, 'false'], + [{ shortTitle: true, title: 'Sola24' }, 'true'], + [{ shortTitle: {}, title: 'Sola24' }, '[object Object]'], + [{ shortTitle: Symbol('foo'), title: 'Sola24' }, 'SoLa24'], + [{ shortTitle: [], title: 'Sola24' }, ''], + [{ shortTitle: /test/, title: 'Sola24' }, '/test/'], [null, ''], [undefined, ''], ])('maps "%s" to "%s"', (input, expected) => { diff --git a/common/helpers/campShortTitle.js b/common/helpers/campShortTitle.js index 85f69cb63e..f173096e03 100644 --- a/common/helpers/campShortTitle.js +++ b/common/helpers/campShortTitle.js @@ -48,8 +48,8 @@ const ADDITIONAL_SHORTNERS = [ ] function campShortTitle(camp) { - if (camp?.shortTitle != null && camp.shortTitle !== '') { - return camp.shortTitle.substring(0, 16) + if (camp?.shortTitle != null && camp.shortTitle !== '' && typeof camp.shortTitle !== 'symbol') { + return `${camp.shortTitle}`.substring(0, 16) } let title = camp?.title ?? ''