Skip to content

Commit

Permalink
Ensure that CSV files don't contain newlines within memo fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jul 17, 2022
1 parent 9d13d94 commit 85984b8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/rest-api",
"version": "3.19.1",
"version": "3.19.2",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"hebcal"
Expand All @@ -21,8 +21,8 @@
"url": "https://github.com/hebcal/hebcal-rest-api/issues"
},
"dependencies": {
"@hebcal/core": "^3.41.1",
"@hebcal/leyning": "^4.13.3"
"@hebcal/core": "^3.42.0",
"@hebcal/leyning": "^4.15.0"
},
"scripts": {
"build": "rollup -c",
Expand All @@ -43,20 +43,20 @@
"verbose": true
},
"devDependencies": {
"@babel/core": "^7.18.5",
"@babel/preset-env": "^7.18.2",
"@babel/register": "^7.17.7",
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/register": "^7.18.6",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"ava": "^4.3.0",
"core-js": "^3.23.2",
"eslint": "^8.18.0",
"ava": "^4.3.1",
"core-js": "^3.23.4",
"eslint": "^8.20.0",
"eslint-config-google": "^0.14.0",
"jsdoc": "^3.6.10",
"jsdoc-to-markdown": "^7.1.1",
"rollup": "^2.75.7",
"rollup": "^2.77.0",
"rollup-plugin-terser": "^7.0.2"
}
}
2 changes: 1 addition & 1 deletion src/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function eventToCsv(e, options) {
if (!memo0 && typeof e.linkedEvent !== 'undefined') {
memo0 = e.linkedEvent.render(options.locale);
}
const memo = memo0.replace(/,/g, ';').replace(/"/g, '\'\'');
const memo = memo0.replace(/,/g, ';').replace(/"/g, '\'\'').replace(/\n/g, ' / ');

const showTimeAs = (timed || (mask & flags.CHAG)) ? 4 : 3;
return `"${subj}",${date},${startTime},${endDate},${endTime},${allDay},"${memo}","${showTimeAs}","${loc}"`;
Expand Down
7 changes: 7 additions & 0 deletions src/csv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ test('HebrewDateEvent', (t) => {
t.is(eventToCsv(ev, {locale: 'he'}), '"כ״ד כִּסְלֵו","12/17/1995",,,,"true","","3","Hebrew Date"');
t.is(eventToCsv(ev, {locale: 'he-x-NoNikud'}), '"כ״ד כסלו","12/17/1995",,,,"true","","3","Hebrew Date"');
});

test('newline', (t) => {
const ev = new HebrewDateEvent(new HDate(2, 'Sivan', 5770));
ev.memo = 'foo\nbar\nbaaz';
const actual = eventToCsv(ev, {locale: 'en'});
t.is(actual, '"2nd of Sivan","5/15/2010",,,,"true","foo / bar / baaz","3","Hebrew Date"');
});

0 comments on commit 85984b8

Please sign in to comment.