Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTransfer's setData, getData, and clearData should allow "same-ness" to ignore charset #2947

Open
rniwa opened this issue Aug 19, 2017 · 13 comments

Comments

@rniwa
Copy link

rniwa commented Aug 19, 2017

When DataTransfer's method such as getData is called, Safari & Chrome both ignores the charset for the sake of equality at least on Mac. This would mean that, for example, setData('text/plain; charset=utf-8', 'foo'); is equivalent to setData('text/plain; charset=Shift_JIS', 'foo');. Firefox seems to treat these MIME types as distinct types even on Mac.

Given there is no mechanism to differentiate text MIME types based on charset on some platforms such as Mac, the spec should allow this behavior.

@annevk
Copy link
Member

annevk commented Aug 19, 2017

What about other parameters? Are parameters basically ignored or would text/plain;x=x and text/plain;x=y be unequal?

@rniwa
Copy link
Author

rniwa commented Aug 20, 2017

In WebKit, we ignore all parameters (inconsistently unfortunately :(). Basically, we treat all text/X; ~ as text/X case-insensitively.

@annevk
Copy link
Member

annevk commented Aug 20, 2017

Seems unfortunate for MIME types such as multipart/form-data;boundary=... but maybe it doesn't matter too much. This is another interesting angle to test for whatwg/mimesniff#30 though. I hope we can figure out a consistent MIME type parsing story at some point.

@rniwa
Copy link
Author

rniwa commented Aug 20, 2017

Oh, I meant just for text/*, not for other MIME types.

@annevk
Copy link
Member

annevk commented Aug 21, 2017

So the charset parameter for application/javascript or application/xml would be significant? But still case-insensitive? Seems like this would need a lot of tests.

@annevk
Copy link
Member

annevk commented Sep 8, 2017

I cannot reproduce this. In Chrome

<script>
d = new DataTransfer();
d.setData("text/HTML;charset=utf-8", "test");
w(d.getData("text/html;"))
</script>

in Live DOM Viewer ends up logging the empty string, not "test". Chrome seems to require a literal ASCII case-insensitive match.

@rniwa
Copy link
Author

rniwa commented Sep 10, 2017

Oh, interesting. Chrome's behavior changes between text/html and text/plain.

<!DOCTYPE html>
<div contenteditable="true" onpaste="test(event.clipboardData)" style="border: solid 1px black; width: 100px; height: 100px;"></div>
<pre id="log"></pre>
<script>
function w(text) {
    document.getElementById('log').textContent += `"${text}"\n`;
}
function test(d) {
    d.setData("text/plain;charset=utf-8", "test");
    w(d.getData("text/plain;"));
}
test(new DataTransfer());
</script>

@annevk
Copy link
Member

annevk commented Sep 11, 2017

So basically if it starts with an ASCII case-insensitive match for text/plain, then parse it as a MIME type and then drop all parameters before comparison. Otherwise just do an ASCII case-insensitive string match.

(Note that text/plain;whatever and text/plain also match. And even just text as that expands to text/plain, but that's already covered.)

@rniwa
Copy link
Author

rniwa commented Sep 11, 2017

iOS WebKit always ignored charset for text/html so I suspect this might be required for mobile compatibility although WebKit's clipboard API support had been weak so it's hard to tell.

@annevk
Copy link
Member

annevk commented Sep 11, 2017

I wouldn't mind changing the above to starting with an ASCII case-insensitive match for text/ or some such. Do you know exactly what you do?

@rniwa
Copy link
Author

rniwa commented Sep 11, 2017

On iOS, we used to strip away all Unicode whitespaces and checked if MIME type started with text/plain case-sensitively. On macOS, we used to check if MIME type started text/plain; case-insensitively without stripping any whitespaces. I'm cleaning up this mess right now.

@annevk
Copy link
Member

annevk commented Sep 11, 2017

Would you parse everything as a MIME type then or some such? E.g., in Chrome text/html; x=y and text/html;x=y are distinct. I'm guessing on iOS they might be identical, but are font/whatever; x=y and font/whatever;x=y?

@rniwa
Copy link
Author

rniwa commented Oct 19, 2017

In iOS, we only treat MIME types that start with text/plain the identical. It doesn't do treat any other MIME type as identical with regards with charset, etc... See https://trac.webkit.org/changeset/221063/webkit/trunk/Source/WebCore/platform/ios/PasteboardIOS.mm (the removed code is what's currently in iOS Safari).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants