Skip to content

Commit dff5e77

Browse files
authored
Merge pull request #1305 from ideal-postcodes/places_fix
2 parents df81680 + 63e2074 commit dff5e77

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

api/app/models/place.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ const seedData = async (directory: string) => {
471471

472472
const typeRegex = /^.*\//;
473473
const parseOsgb = (val: string) => parseInt(val, 10) || "";
474+
const stripBom = (val: string) => val.replace(/^\uFEFF/, "");
474475
const transformExceptions = {
476+
code: stripBom,
475477
northings: parseOsgb,
476478
eastings: parseOsgb,
477479
min_eastings: parseOsgb,

test/place.unit.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ describe("Place Model", () => {
5858
const result = await query(q);
5959
assert.equal(result.rows[0].count, placesEntriesCount);
6060
});
61+
62+
it("strips BOM characters from code field", async () => {
63+
// BOM (U+FEFF) can appear at start of CSV files and pollute first field
64+
const q = `SELECT code FROM ${Place.relation.relation}`;
65+
const result = await query(q);
66+
result.rows.forEach((row) => {
67+
assert.isFalse(
68+
row.code.startsWith("\uFEFF"),
69+
`code "${row.code}" should not start with BOM character`
70+
);
71+
});
72+
});
6173
});
6274

6375
describe("#populateLocation", () => {

test/postcode.regression.unit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe("Postcode data regression testing", function () {
155155
admin_district: "Channel Islands",
156156
parish: null,
157157
admin_county: null,
158-
admin_ward: null,
158+
admin_ward: "Channel Islands (pseudo)",
159159
ccg: null,
160160
ccg_code: null,
161161
nuts: null,

0 commit comments

Comments
 (0)