diff --git a/source/changelog.txt b/source/changelog.txt index 86ed81d..fda38f6 100644 --- a/source/changelog.txt +++ b/source/changelog.txt @@ -8,6 +8,7 @@ #### Removed #### Fixed - Use ES modules correctly +- Trim events' location #### Security ### [0.7.0] - 2021-12-23 diff --git a/source/front/formatter-test.js b/source/front/formatter-test.js index 0e3dcf1..d34dd60 100644 --- a/source/front/formatter-test.js +++ b/source/front/formatter-test.js @@ -53,16 +53,21 @@ test('#formatDate second date is null with short offset name', (t) => { }) test('#formatLocation both parameters', (t) => { - const date = Formatter.formatLocation({ description: 'a', locality: 'b' }) - t.is(date, 'a, b') + const location = Formatter.formatLocation({ description: 'a', locality: 'b' }) + t.is(location, 'a, b') }) test('#formatLocation description only', (t) => { - const date = Formatter.formatLocation({ description: 'a' }) - t.is(date, 'a') + const location = Formatter.formatLocation({ description: 'a' }) + t.is(location, 'a') +}) + +test('#formatLocation description with space only', (t) => { + const location = Formatter.formatLocation({ description: ' ' }) + t.is(location, '') }) test('#formatLocation locality only', (t) => { - const date = Formatter.formatLocation({ locality: 'a' }) - t.is(date, 'a') + const location = Formatter.formatLocation({ locality: 'a' }) + t.is(location, 'a') }) diff --git a/source/front/formatter.js b/source/front/formatter.js index 82ff161..614db12 100644 --- a/source/front/formatter.js +++ b/source/front/formatter.js @@ -31,8 +31,8 @@ export default class Formatter { static formatLocation({ description, locality }) { let location = '' - if (description) { - location += description + if (description && description.trim()) { + location += description.trim() } if (location && locality) { location += ', '