-
Notifications
You must be signed in to change notification settings - Fork 61
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 (#560)
* fix(core): fix hash collisions with at rules * Update packages/core/src/runtime/utils/hashPropertyKey.ts Co-authored-by: ling1726 <lingfangao@hotmail.com> --------- Co-authored-by: ling1726 <lingfangao@hotmail.com>
- Loading branch information
1 parent
f545363
commit 80ca330
Showing
11 changed files
with
83 additions
and
47 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
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(`"B3v6anr"`); | ||
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