Skip to content

Commit

Permalink
Merge pull request #6 from vtex-apps/fix/validatemodifier
Browse files Browse the repository at this point in the history
Fix/validatemodifier
  • Loading branch information
jgfidelis authored Oct 4, 2019
2 parents 6d7adbf + 3f257a7 commit c18b0a9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Also allow `-` on handle modfifiers.

## [0.3.0] - 2019-10-03
### Added
Expand Down
4 changes: 2 additions & 2 deletions react/__tests__/applyModifiers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ describe('applyModifier', () => {
'vtex-app-2-x-handle vtex-app-2-x-handle--blockClass vtex-app-2-x-handle--ok vtex-app-2-x-handle--blockClass--ok'
)
})
it('should not apply a modifier with spaces or dashes', () => {
it('should not apply a modifier with spaces, should allow with dashes', () => {
const handle = 'vtex-app-2-x-handle vtex-app-2-x-handle--blockClass'
const modifiers = ['ok', 'test 1', 'test-2', 'test\t3', 'test\n4']

const modified = applyModifiers(handle, modifiers)

expect(modified).toBe(
'vtex-app-2-x-handle vtex-app-2-x-handle--blockClass vtex-app-2-x-handle--ok vtex-app-2-x-handle--blockClass--ok'
'vtex-app-2-x-handle vtex-app-2-x-handle--blockClass vtex-app-2-x-handle--ok vtex-app-2-x-handle--blockClass--ok vtex-app-2-x-handle--test-2 vtex-app-2-x-handle--blockClass--test-2'
)
})
it('should not apply a modifier if its empty', () => {
Expand Down
4 changes: 2 additions & 2 deletions react/applyModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const validateModifier = (modifier: string) => {
return false
}

if (/[^A-z0-9]/.test(modifier)) {
if (/[^A-z0-9-]/.test(modifier)) {
console.error(
`Invalid modifier on \`cssHandles.applyModifier\`. Modifiers should contain only letters and numbers`
`Invalid modifier on \`cssHandles.applyModifier\`. Modifiers should contain only letters, numbers or -`
)
return false
}
Expand Down

0 comments on commit c18b0a9

Please sign in to comment.