Skip to content

Commit

Permalink
Strip nulls from data
Browse files Browse the repository at this point in the history
  • Loading branch information
john-gom committed Nov 1, 2023
1 parent ced861b commit 974390c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/domain/services/import.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('importFromMongo', () => {

// THEN: Product should be loaded with nuls stripped
const ingredientsNew = await app.get(EntityManager).find(ProductIngredientsTag, {
product: { id: productIdNew},
product: { code: productIdNew},
});

expect(ingredientsNew).toHaveLength(1);
Expand Down
12 changes: 11 additions & 1 deletion src/domain/services/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class ImportService {
}

/** Populate a Product record from MongoDB document */
nulRegex = /\0/g;
async fixupProduct(
update: boolean,
updateId: string,
Expand All @@ -113,7 +114,16 @@ export class ImportService {
const product = await this.findOrNewProduct(update, data);
const dataToStore = {};
for (const key of this.tags) {
dataToStore[key] = data[key];
const tagData = data[key] as string[];
if (tagData) {
// Strip out any nul characters
for (const [index, value] of tagData.entries()) {
if (value.includes('\u0000')) {
tagData[index] = value.replace(this.nulRegex, '');
}
}
dataToStore[key] = tagData;
}
}
product.data = dataToStore;
product.name = data.product_name;
Expand Down

0 comments on commit 974390c

Please sign in to comment.