-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fix hash collisions with at rules
- Loading branch information
1 parent
3cac9f0
commit fe1937f
Showing
11 changed files
with
106 additions
and
49 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@griffel-core-3f1edf4d-9560-425a-bd42-e112f2ced10f.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix(core): fix hash collisions with at rules", | ||
"packageName": "@griffel/core", | ||
"email": "olfedias@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { hashClassName } from './hashClassName'; | ||
|
||
const defaultOptions = { | ||
property: 'color', | ||
selector: '', | ||
value: 'red', | ||
|
||
salt: '', | ||
}; | ||
const defaultAtRules = { | ||
container: '', | ||
media: '', | ||
layer: '', | ||
supports: '', | ||
}; | ||
|
||
describe('hashClassName', () => { | ||
it('should hash the className', () => { | ||
expect(hashClassName(defaultOptions, defaultAtRules)).toMatchInlineSnapshot(`"fe3e8s9"`); | ||
}); | ||
|
||
it('should generate non-colliding hashes', () => { | ||
const hashA = hashClassName(defaultOptions, { ...defaultAtRules, container: '(min-width: 500px)' }); | ||
const hashB = hashClassName(defaultOptions, { ...defaultAtRules, media: '(min-width: 500px)' }); | ||
|
||
expect(hashA).toMatchInlineSnapshot(`"f18ymuke"`); | ||
expect(hashB).toMatchInlineSnapshot(`"f16oyr76"`); | ||
expect(hashA).not.toBe(hashB); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { hashPropertyKey } from './hashPropertyKey'; | ||
|
||
const defaultAtRules = { container: '', media: '', supports: '', layer: '' }; | ||
|
||
describe('hashPropertyKey', () => { | ||
it('generates hashes that always start with letters', () => { | ||
const atRules = { container: '', media: '', supports: '', layer: '' }; | ||
expect(hashPropertyKey('', 'color', defaultAtRules)).toBe('sj55zd'); | ||
expect(hashPropertyKey('', 'display', defaultAtRules)).toBe('mc9l5x'); | ||
|
||
expect(hashPropertyKey('', 'backgroundColor', defaultAtRules)).toBe('De3pzq'); | ||
expect(hashPropertyKey(':hover', 'color', defaultAtRules)).toBe('Bi91k9c'); | ||
}); | ||
|
||
expect(hashPropertyKey('', 'color', atRules)).toBe('sj55zd'); | ||
expect(hashPropertyKey('', 'display', atRules)).toBe('mc9l5x'); | ||
it('generates non-colliding hashes', () => { | ||
const hashA = hashPropertyKey('', 'color', { ...defaultAtRules, container: '(min-width: 500px)' }); | ||
const hashB = hashPropertyKey('', 'color', { ...defaultAtRules, media: '(min-width: 500px)' }); | ||
|
||
expect(hashPropertyKey('', 'backgroundColor', atRules)).toBe('De3pzq'); | ||
expect(hashPropertyKey(':hover', 'color', atRules)).toBe('Bi91k9c'); | ||
expect(hashA).toMatchInlineSnapshot(`"Bhkzl7a"`); | ||
expect(hashB).toMatchInlineSnapshot(`"zc7s4b"`); | ||
expect(hashA).not.toBe(hashB); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters