Skip to content

Conversation

@marchaos
Copy link

@marchaos marchaos commented Dec 16, 2025

Problem

DataTransfer.getData() performs exact string matching on format types. However, according to the HTML spec, format strings should be normalized:

  • "text" should be treated as "text/plain"
  • "url" should be treated as "text/uri-list"
  • Format comparison should be case-insensitive

This causes issues when testing libraries (like @testing-library/user-event) use shorthand format names. For example, user.paste('data') adds data with type "text", but application code calling evt.clipboardData.getData('text/plain') returns an empty string.

Solution

Added format normalization in getData() that:

  1. Converts formats to lowercase
  2. Maps "text""text/plain"
  3. Maps "url""text/uri-list"

Reference

https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-getdata

Testing

Added tests for format normalization behavior.

According to the HTML spec, getData() should normalize format strings:
- "text" should be treated as "text/plain"
- "url" should be treated as "text/uri-list"
- Format comparison should be case-insensitive

This fixes issues with clipboard operations when testing libraries
(like user-event) use shorthand format names.

Reference: https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-getdata
@marchaos marchaos force-pushed the fix/datatransfer-format-normalization branch from 199f1ff to 41155c7 Compare December 21, 2025 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant