diff --git a/api/app/models/place.ts b/api/app/models/place.ts index a03ef860..aad1680d 100644 --- a/api/app/models/place.ts +++ b/api/app/models/place.ts @@ -471,7 +471,9 @@ const seedData = async (directory: string) => { const typeRegex = /^.*\//; const parseOsgb = (val: string) => parseInt(val, 10) || ""; + const stripBom = (val: string) => val.replace(/^\uFEFF/, ""); const transformExceptions = { + code: stripBom, northings: parseOsgb, eastings: parseOsgb, min_eastings: parseOsgb, diff --git a/test/place.unit.ts b/test/place.unit.ts index eb225e34..93f103df 100644 --- a/test/place.unit.ts +++ b/test/place.unit.ts @@ -58,6 +58,18 @@ describe("Place Model", () => { const result = await query(q); assert.equal(result.rows[0].count, placesEntriesCount); }); + + it("strips BOM characters from code field", async () => { + // BOM (U+FEFF) can appear at start of CSV files and pollute first field + const q = `SELECT code FROM ${Place.relation.relation}`; + const result = await query(q); + result.rows.forEach((row) => { + assert.isFalse( + row.code.startsWith("\uFEFF"), + `code "${row.code}" should not start with BOM character` + ); + }); + }); }); describe("#populateLocation", () => { diff --git a/test/postcode.regression.unit.ts b/test/postcode.regression.unit.ts index 4c8c74b3..c11c8a53 100644 --- a/test/postcode.regression.unit.ts +++ b/test/postcode.regression.unit.ts @@ -155,7 +155,7 @@ describe("Postcode data regression testing", function () { admin_district: "Channel Islands", parish: null, admin_county: null, - admin_ward: null, + admin_ward: "Channel Islands (pseudo)", ccg: null, ccg_code: null, nuts: null,