diff --git a/src/utils/dataTransfer/DataTransfer.ts b/src/utils/dataTransfer/DataTransfer.ts index fb13967a..660ebe86 100644 --- a/src/utils/dataTransfer/DataTransfer.ts +++ b/src/utils/dataTransfer/DataTransfer.ts @@ -62,15 +62,22 @@ class DataTransferItemListStub } } +function normalizeFormat(format: string) { + return format.toLowerCase() +} + function getTypeMatcher(type: string, exact: boolean) { - const [group, sub] = type.split('/') + const normalizedType = normalizeFormat(type) + const [group, sub] = normalizedType.split('/') const isGroup = !sub || sub === '*' return (item: DataTransferItem) => { + const normalizedItemType = normalizeFormat(item.type) + return exact - ? item.type === (isGroup ? group : type) + ? normalizedItemType === (isGroup ? group : normalizedType) : isGroup - ? item.type.startsWith(`${group}/`) - : item.type === group + ? normalizedItemType.startsWith(`${group}/`) + : normalizedItemType === group } } diff --git a/tests/clipboard/paste.ts b/tests/clipboard/paste.ts index cd5eb967..0fa4c608 100644 --- a/tests/clipboard/paste.ts +++ b/tests/clipboard/paste.ts @@ -132,6 +132,21 @@ test('should replace selected text all at once', async () => { expect(element).toHaveValue('hello friend') }) +test('should ignore format case', async () => { + const {element, user} = setup('') + element.addEventListener('paste', event => { + event.preventDefault() + + const data = event.clipboardData?.getData('Text') + + element.value = data ?? '' + }) + + await user.paste('friend') + + expect(element).toHaveValue('friend') +}) + describe('without Clipboard API', () => { beforeEach(() => { Object.defineProperty(window.navigator, 'clipboard', { diff --git a/tests/utils/dataTransfer/DataTransfer.ts b/tests/utils/dataTransfer/DataTransfer.ts index 7b63b03c..e9e89764 100644 --- a/tests/utils/dataTransfer/DataTransfer.ts +++ b/tests/utils/dataTransfer/DataTransfer.ts @@ -23,6 +23,7 @@ describe('create DataTransfer', () => { expect(dt.getData('text/html')).toBe('bar') expect(dt.getData('text/*')).toBe('foo') expect(dt.getData('text')).toBe('foo') + expect(dt.getData('Text')).toBe('foo') dt.clearData() dt.setData('text', 'baz')