File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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" , ( ) => {
You can’t perform that action at this time.
0 commit comments