inlinestyler icon indicating copy to clipboard operation
inlinestyler copied to clipboard

0.2.1+ no longer supports stylesheets in data URIs

Open dato opened this issue 9 years ago • 3 comments

It is possible to embed CSS inside the <style> element using the data: URI scheme. Like this:

<link rel="stylesheet" href="data:text/css,EMBEDDED_CSS_GOES_HERE">

This worked in 0.2.0, but doesn’t work in 0.2.1 with the move from urllib.urlopen() to python-requests.

It’d be nice to get this working again, though it’s arguably a requests issue.


I took a quick at requests, but I couldn’t determine if they have support for RFC 2397 (which defines the data: scheme).

I suggest leaving this bug open until either of us the time to investigate RFC2397 support in python-requests.

dato avatar Aug 14 '15 03:08 dato

Interesting - requests is certainly the proximate cause, but I'd still call it an inlinestyler issue as it's something that used to work but doesn't anymore.

To help debugging when one of us gets to it, can you post an example here of what used to work?

dlanger avatar Aug 14 '15 19:08 dlanger

Hey! Thanks for the quick reply. :-)

Here’s an example HTML file, and the command I run on it:

<!DOCTYPE html>
<html>
<head>
<link href="data:text/css,p%20%7B%0A%20%20border%3A%200%3B%0A%7D%0A" rel="stylesheet" type="text/css">
</head>
<body>
<p>Hello.</p>
</body>
</html>
% python -c 'from inlinestyler.utils import inline_css; print inline_css(open("test.html").read())'
<html>
<head>
</head>
<body>
<p style="border: 0">Hello.</p>
</body>
</html>

(That's with 0.2.0.)

Cheers, -d

dato avatar Aug 14 '15 20:08 dato

The actual error that requests is throwing is InvalidSchema: No connection adapters were found for 'data:text/css,..., which is its way of saying that it doesn't know how to handle (can't find a transport adapter for) a data: URI

Looking at the source, it only comes baked-in with http: and https: adapters, which is...surprising. If you can find a data: adapter that someone's written I'll glady bring it in as a requirement, but I don't see writing one from scratch as something that I'll get done in the medium-term.

In the meantime, I'll leave this open as it's a legit regression.

dlanger avatar Nov 01 '15 20:11 dlanger