Skip to content

Commit

Permalink
isPropValid: Add custom props to blacklist (#15)
Browse files Browse the repository at this point in the history
* isPropValid: Add custom props to blacklist

This update adjusts the `isPropValid` function to add a custom black list,
starting with the prop `action`.

In HSDS: React development, we noticed that the prop `action` leaked through.

* Improve regex for OTHER_ATTRIBUTE_REGEX
  • Loading branch information
Jon Quach authored Feb 28, 2019
1 parent f413d40 commit 8742237
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/__tests__/isPropValid.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import isPropValid from '../isPropValid'

test('Filters out other stray props', () => {
const props = ['action']

props.forEach(prop => {
expect(isPropValid(prop)).toBeFalsy()
})
})
11 changes: 9 additions & 2 deletions src/isPropValid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@ const isCustomAttribute = RegExp.prototype.test.bind(
new RegExp(`^(x|data|aria)-[${ATTRIBUTE_NAME_CHAR}]*$`)
)

export default (name: string) =>
ATTRIBUTE_REGEX.test(name) || isCustomAttribute(name.toLowerCase())
/* Custom filter list */
const OTHER_ATTRIBUTE_REGEX = /^(action)/g

export default (name: string): boolean => {
return (
(ATTRIBUTE_REGEX.test(name) || isCustomAttribute(name.toLowerCase())) &&
!OTHER_ATTRIBUTE_REGEX.test(name)
)
}

0 comments on commit 8742237

Please sign in to comment.