diff --git a/src/lib/filters/entities.js b/src/lib/filters/entities.js index 17fa9ad8..8141084f 100644 --- a/src/lib/filters/entities.js +++ b/src/lib/filters/entities.js @@ -92,7 +92,9 @@ export const shouldKeepEntityByAttribute = ( const isValid = Object.keys(whitelist).every((attr) => { const regex = new RegExp(whitelist[attr]) - return regex.test(data[attr]) + const hasData = data.hasOwnProperty(attr) + + return hasData && regex.test(data[attr]) }) return isValid diff --git a/src/lib/filters/entities.test.js b/src/lib/filters/entities.test.js index 8f0b24a7..4ab89b32 100644 --- a/src/lib/filters/entities.test.js +++ b/src/lib/filters/entities.test.js @@ -224,6 +224,26 @@ describe("entities", () => { }) }) + it("attribute not defined on entities", () => { + expect( + shouldKeepEntityByAttribute( + [ + { + type: "LINK", + whitelist: { + id: ".*", + }, + }, + ], + "LINK", + { + href: "#_msocom_1", + target: "_blank", + }, + ), + ).toBe(false) + }) + describe("defaults", () => { it("missing config", () => { expect(