🐛 Handled BOM character for Unicode encoded file uploads (#17104)
fixes https://github.com/TryGhost/Ghost/issues/16917 refs https://github.com/TryGhost/Ghost/issues/16917#issuecomment-1602984601 Co-authored-by: Princi Vershwal <princi.vershwal@Princis-MacBook-Pro.local>
This commit is contained in:
parent
9e6c800e38
commit
21085d0732
@ -15,11 +15,11 @@ module.exports = (path, headerMapping, defaultLabels = []) => {
|
||||
const csvParserStream = papaparse.parse(papaparse.NODE_STREAM_INPUT, {
|
||||
header: true,
|
||||
transformHeader(_header) {
|
||||
if (!headerMapping || !Reflect.has(headerMapping, _header)) {
|
||||
const cleanHeader = _header.replace(papaparse.BYTE_ORDER_MARK, ''); //Removing BOM characters for Unicode-based encodings
|
||||
if (!headerMapping || !Reflect.has(headerMapping, cleanHeader)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return headerMapping[_header];
|
||||
return headerMapping[cleanHeader];
|
||||
},
|
||||
transform(value, header) {
|
||||
if (header === 'labels') {
|
||||
|
3
ghost/members-csv/test/fixtures/single-column-with-header-bom.csv
vendored
Normal file
3
ghost/members-csv/test/fixtures/single-column-with-header-bom.csv
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
email
|
||||
jbloggs@example.com
|
||||
test@example.com
|
|
@ -35,6 +35,24 @@ describe('parse', function () {
|
||||
assert.equal(result.length, 0);
|
||||
});
|
||||
|
||||
it('one column with bom', async function () {
|
||||
const filePath = csvPath + 'single-column-with-header-bom.csv';
|
||||
const result = await parse(filePath, DEFAULT_HEADER_MAPPING);
|
||||
|
||||
assert.ok(result);
|
||||
assert.equal(result.length, 2);
|
||||
assert.equal(result[0].email, 'jbloggs@example.com');
|
||||
assert.equal(result[1].email, 'test@example.com');
|
||||
});
|
||||
|
||||
it('one column with bom and without header mapping returns empty result', async function () {
|
||||
const filePath = csvPath + 'single-column-with-header-bom.csv';
|
||||
const result = await parse(filePath);
|
||||
|
||||
assert.ok(result);
|
||||
assert.equal(result.length, 0);
|
||||
});
|
||||
|
||||
it('two columns, 1 filter', async function () {
|
||||
const filePath = csvPath + 'two-columns-with-header.csv';
|
||||
const result = await parse(filePath, DEFAULT_HEADER_MAPPING);
|
||||
|
Loading…
Reference in New Issue
Block a user