Skip to content

Commit

Permalink
fix: quotes in key crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
MadCcc committed Mar 9, 2023
1 parent a00181f commit 8f9b2e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

/**
* We trade Map as deps which may change with same value but different ref object.
* We should make it as hash for deps
Expand All @@ -18,6 +20,6 @@ export function stringify<K extends string | number | symbol, V>(obj: Record<K,
}

const RC_TABS_DOUBLE_QUOTE = 'TABS_DQ';
export function genDataNodeKey(key: string): string {
return key.replace(/"/g, RC_TABS_DOUBLE_QUOTE);
export function genDataNodeKey(key: React.Key): string {
return String(key).replace(/"/g, RC_TABS_DOUBLE_QUOTE);
}
4 changes: 4 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,5 +513,9 @@ describe('Tabs.Basic', () => {

it('key contains double quote should not crash', () => {
render(<Tabs items={[{key: '"key"', label: 'test'}]} />)
});

it('key could be number', () => {
render(<Tabs items={[{key: 1 as any, label: 'test'}]} />)
})
});

0 comments on commit 8f9b2e5

Please sign in to comment.