Skip to content

Commit

Permalink
campShortTitle.js: fix error for non string camp.shortTitle
Browse files Browse the repository at this point in the history
Fixes #6363
  • Loading branch information
BacLuc committed Nov 16, 2024
1 parent e89dddd commit 60fd278
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions common/helpers/__tests__/campShortTitle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions common/helpers/campShortTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? ''
Expand Down

0 comments on commit 60fd278

Please sign in to comment.