Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 880962714e11143450d39dae76d4b1987171369c
https://github.com/WebKit/WebKit/commit/880962714e11143450d39dae76d4b1987171369c
Author: Ahmad Saleem <[email protected]>
Date: 2026-08-16 (Sun, 16 Aug 2026)
Changed paths:
M LayoutTests/editing/pasteboard/dataTransfer-setData-getData-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/html/editing/dnd/datastore/datatransfer-getdata-url-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/html/editing/dnd/datastore/datatransfer-getdata-url.html
M Source/WebCore/dom/DataTransfer.cpp
Log Message:
-----------
DataTransfer.getData("url") returns the whole text/uri-list instead of its
first URL
https://bugs.webkit.org/show_bug.cgi?id=321841
rdar://184988378
Reviewed by Chris Dumez.
Per the specification [1], getData() step 6 says:
"If format equals "url", change it to "text/uri-list" and set
convert-to-URL to true."
and step 9 then acts on that flag:
"If convert-to-URL is true, then parse result as appropriate for
text/uri-list data, and then set result to the first URL from the list,
if any, or the empty string otherwise."
Comment lines - those beginning with "#" per RFC 2483 [2] - are not URLs and are
skipped when finding that first URL.
WebKit implemented only half of this. normalizeType() performs the step 6 rename
of "url" to "text/uri-list", but nothing ever performed step 9, so
getData("url")
handed back the raw list: every URL joined by its original line endings, comment
lines included. Even a single URL followed by a trailing newline came back with
the newline attached.
The reason this went unnoticed for so long is that the platform read path
collapses to one URL by accident of implementation - urlStringsFromPasteboard()
goes through [NSURL URLFromPasteboard:], which yields a single absolute URL - so
getData("url") looked correct for anything copied from another application. The
bug was only observable for a text/uri-list a page wrote itself with setData(),
which is served by the same-origin custom data path.
Compute the convert-to-URL flag from the requested format before normalizeType()
collapses it, so text/uri-list and text/uri-list;charset=utf-8 keep returning
their data verbatim, then reduce the result to its first URL.
DataTransferItem.getAsString() reads through getDataForItem() and is left alone,
since the specification puts this step in getData() only.
Testing across engines: Chrome matches [1] in all cases. Firefox matches except
when a blank line precedes the first URL, where it returns the empty string - it
discards comment lines but not blank ones. RFC 2483 [2] only specifies the
treatment of comment lines, so that case is under-specified; this change follows
Chrome and the "first URL from the list" wording of step 9, and the new test
isolates it in its own subtest.
editing/pasteboard/dataTransfer-setData-getData.html has asserted the correct
behavior since it was written, with five FAIL lines checked into its expected
results - one per convert-to-URL case. Those now pass; rebaseline.
[1] https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-getdata
[2] https://datatracker.ietf.org/doc/html/rfc2483#section-5
Test:
imported/w3c/web-platform-tests/html/editing/dnd/datastore/datatransfer-getdata-url.html
* LayoutTests/editing/pasteboard/dataTransfer-setData-getData-expected.txt:
Rebaselined
*
LayoutTests/imported/w3c/web-platform-tests/html/editing/dnd/datastore/datatransfer-getdata-url-expected.txt:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/html/editing/dnd/datastore/datatransfer-getdata-url.html:
Added.
* Source/WebCore/dom/DataTransfer.cpp:
(WebCore::firstURLFromURIList):
(WebCore::DataTransfer::getData const):
Canonical link: https://commits.webkit.org/319267@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications