Skip to content

Commit

Permalink
feat(api): add ability for whitelist to filter by undefined attribute
Browse files Browse the repository at this point in the history
The entities whitelist can now specify an attribute undefined on the target data. If the attribute is undefined, the entity will be filtered out.
  • Loading branch information
thibaudcolas committed Jan 17, 2018
1 parent 47b86a2 commit a4af845
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/filters/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/lib/filters/entities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a4af845

Please sign in to comment.