Stranger6667 / css-inline

High-performance library for inlining CSS into HTML 'style' attributes
https://css-inline.org/
MIT License
232 stars 29 forks source link

Double quotes in font-family name break generated style attribute #333

Closed Bartvaderkin closed 4 months ago

Bartvaderkin commented 6 months ago

I found this CSS rule with double quotes in the font-family values, and it looks like the inliner doesn't transform the quote style so the copied values break the double quotes of the generated style attribute:

Our case is easily fixable by using single quotes (and of course these particular font names don't even have to be quoted), but it feels like there could be an issue:

h1 {
    color: #000000;
    font-family: "Ubuntu", "Helvetica", Arial, sans-serif;
    font-weight: 600;
    padding: 0;
    margin: 0;
}
<h1 style="color: #0084BB;font-family: "Ubuntu", "Helvetica", Arial, sans-serif;font-weight: 600;padding: 0;margin: 0">test</h1>
---------------------------------------^

This is on Python 3.11.5 and css-inline 0.13.0

Stranger6667 commented 6 months ago

Hi @Bartvaderkin!

Thanks for reporting - I thought I fixed this a while ago (there are also tests for it), but apparently it didn't work. Let me check it

Stranger6667 commented 6 months ago

Here is what I have as input to the css-inline CLI:

<html>
<head>
    <style>
        h1 {
            color: #000000;
            font-family: "Ubuntu", "Helvetica", Arial, sans-serif;
            font-weight: 600;
            padding: 0;
            margin: 0;
        }
    </style>
</head>
<body>
<h1>Test</h1>
</body>
</html>

The result:

<html><head>

</head>
<body>
<h1 style="color: #000000;font-family: 'Ubuntu', 'Helvetica', Arial, sans-serif;font-weight: 600;padding: 0;margin: 0;">Test</h1>

</body></html>

Which seems to be correct. For Python:

In [1]: import css_inline

In [2]: html = """<html>
   ...: <head>
   ...:     <style>
   ...:         h1 {
   ...:             color: #000000;
   ...:             font-family: "Ubuntu", "Helvetica", Arial, sans-serif;
   ...:             font-weight: 600;
   ...:             padding: 0;
   ...:             margin: 0;
   ...:         }
   ...:     </style>
   ...: </head>
   ...: <body>
   ...: <h1>Test</h1>
   ...: </body>
   ...: </html>
   ...: """

In [3]: print(css_inline.inline(html))
<html><head>

</head>
<body>
<h1 style="color: #000000;font-family: 'Ubuntu', 'Helvetica', Arial, sans-serif;font-weight: 600;padding: 0;margin: 0;">Test</h1>

</body></html>

The example above uses the latest version from the repository which is the same as 0.13.0 (there were no relevant changes from that point).

Could you, please, share the content of css_inline.__build__ ?

Mine looks like this ``` In [4]: css_inline.__build__ Out[4]: {'build': {'rustc': '/home/stranger6667/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc', 'rustc-version': 'rustc 1.75.0 (82e1608df 2023-12-21)', 'opt-level': '3', 'debug': False, 'jobs': 12}, 'info-time': datetime.datetime(2024, 2, 7, 12, 18, 15, tzinfo=datetime.timezone.utc), 'dependencies': {'addr2line': '0.21.0', 'adler': '1.0.2', 'android-tzdata': '0.1.1', 'android_system_properties': '0.1.5', 'autocfg': '1.1.0', 'backtrace': '0.3.69', 'base64': '0.21.5', 'bitflags': '2.4.1', 'built': '0.7.1', 'bumpalo': '3.14.0', 'byteorder': '1.5.0', 'bytes': '1.5.0', 'cargo-lock': '9.0.0', 'cc': '1.0.83', 'cfg-if': '1.0.0', 'chrono': '0.4.31', 'core-foundation': '0.9.4', 'core-foundation-sys': '0.8.6', 'crossbeam-deque': '0.8.3', 'crossbeam-epoch': '0.9.15', 'crossbeam-utils': '0.8.16', 'css-inline': '0.13.0', 'css-inline-python': '0.13.0', 'cssparser': '0.31.2', 'cssparser-macros': '0.6.1', 'derive_more': '0.99.17', 'dtoa': '1.0.9', 'dtoa-short': '0.3.4', 'either': '1.9.0', 'encoding_rs': '0.8.33', 'equivalent': '1.0.1', 'fnv': '1.0.7', 'form_urlencoded': '1.2.1', 'futf': '0.1.5', 'futures-channel': '0.3.30', 'futures-core': '0.3.30', 'futures-io': '0.3.30', 'futures-sink': '0.3.30', 'futures-task': '0.3.30', 'futures-util': '0.3.30', 'fxhash': '0.2.1', 'getrandom': '0.2.11', 'gimli': '0.28.1', 'h2': '0.3.22', 'hashbrown': '0.14.3', 'heck': '0.4.1', 'hermit-abi': '0.3.3', 'html5ever': '0.26.0', 'http': '0.2.11', 'http-body': '0.4.6', 'httparse': '1.8.0', 'httpdate': '1.0.3', 'hyper': '0.14.28', 'hyper-rustls': '0.24.2', 'iana-time-zone': '0.1.58', 'iana-time-zone-haiku': '0.1.2', 'idna': '0.5.0', 'indexmap': '2.1.0', 'indoc': '2.0.4', 'ipnet': '2.9.0', 'itoa': '1.0.9', 'js-sys': '0.3.66', 'libc': '0.2.150', 'lock_api': '0.4.11', 'log': '0.4.20', 'mac': '0.1.1', 'markup5ever': '0.11.0', 'memchr': '2.6.4', 'memoffset': '0.9.0', 'mime': '0.3.17', 'miniz_oxide': '0.7.1', 'mio': '0.8.10', 'new_debug_unreachable': '1.0.4', 'num-traits': '0.2.17', 'num_cpus': '1.16.0', 'object': '0.32.2', 'once_cell': '1.18.0', 'parking_lot': '0.12.1', 'parking_lot_core': '0.9.9', 'percent-encoding': '2.3.1', 'phf': '0.11.2', 'phf_codegen': '0.10.0', 'phf_generator': '0.11.2', 'phf_macros': '0.11.2', 'phf_shared': '0.11.2', 'pin-project-lite': '0.2.13', 'pin-utils': '0.1.0', 'ppv-lite86': '0.2.17', 'precomputed-hash': '0.1.1', 'proc-macro2': '1.0.70', 'pyo3': '0.20.0', 'pyo3-build-config': '0.20.0', 'pyo3-built': '0.4.7', 'pyo3-ffi': '0.20.0', 'pyo3-macros': '0.20.0', 'pyo3-macros-backend': '0.20.0', 'quote': '1.0.33', 'rand': '0.8.5', 'rand_chacha': '0.3.1', 'rand_core': '0.6.4', 'rayon': '1.8.0', 'rayon-core': '1.12.0', 'redox_syscall': '0.4.1', 'reqwest': '0.11.23', 'ring': '0.17.6', 'rustc-demangle': '0.1.23', 'rustc-hash': '1.1.0', 'rustls': '0.21.10', 'rustls-pemfile': '1.0.4', 'rustls-webpki': '0.101.7', 'ryu': '1.0.16', 'scopeguard': '1.2.0', 'sct': '0.7.1', 'selectors': '0.25.0', 'semver': '1.0.20', 'serde': '1.0.193', 'serde_derive': '1.0.193', 'serde_json': '1.0.109', 'serde_spanned': '0.6.4', 'serde_urlencoded': '0.7.1', 'servo_arc': '0.3.0', 'siphasher': '0.3.11', 'slab': '0.4.9', 'smallvec': '1.11.2', 'socket2': '0.5.5', 'spin': '0.9.8', 'stable_deref_trait': '1.2.0', 'string_cache': '0.8.7', 'string_cache_codegen': '0.5.2', 'syn': '2.0.39', 'system-configuration': '0.5.1', 'system-configuration-sys': '0.5.0', 'target-lexicon': '0.12.12', 'tendril': '0.4.3', 'tinyvec': '1.6.0', 'tinyvec_macros': '0.1.1', 'tokio': '1.35.1', 'tokio-rustls': '0.24.1', 'tokio-util': '0.7.10', 'toml': '0.7.8', 'toml_datetime': '0.6.5', 'toml_edit': '0.19.15', 'tower-service': '0.3.2', 'tracing': '0.1.40', 'tracing-core': '0.1.32', 'try-lock': '0.2.5', 'unicode-bidi': '0.3.13', 'unicode-ident': '1.0.12', 'unicode-normalization': '0.1.22', 'unindent': '0.2.3', 'untrusted': '0.9.0', 'url': '2.5.0', 'utf-8': '0.7.6', 'want': '0.3.1', 'wasi': '0.11.0+wasi-snapshot-preview1', 'wasm-bindgen': '0.2.89', 'wasm-bindgen-backend': '0.2.89', 'wasm-bindgen-futures': '0.4.39', 'wasm-bindgen-macro': '0.2.89', 'wasm-bindgen-macro-support': '0.2.89', 'wasm-bindgen-shared': '0.2.89', 'web-sys': '0.3.66', 'webpki-roots': '0.25.3', 'windows-core': '0.51.1', 'windows-sys': '0.48.0', 'windows-targets': '0.48.5', 'windows_aarch64_gnullvm': '0.48.5', 'windows_aarch64_msvc': '0.48.5', 'windows_i686_gnu': '0.48.5', 'windows_i686_msvc': '0.48.5', 'windows_x86_64_gnu': '0.48.5', 'windows_x86_64_gnullvm': '0.48.5', 'windows_x86_64_msvc': '0.48.5', 'winnow': '0.5.21', 'winreg': '0.50.0'}, 'features': [], 'host': {'triple': 'x86_64-unknown-linux-gnu'}, 'target': {'arch': 'x86_64', 'os': 'linux', 'family': 'unix', 'env': 'gnu', 'triple': 'x86_64-unknown-linux-gnu', 'endianness': 'little', 'pointer-width': '64', 'profile': 'release'}} ```
Stranger6667 commented 6 months ago

@Bartvaderkin checking if you have any updates on this issue?

Stranger6667 commented 5 months ago

Hey @Bartvaderkin

Are there any updates? Otherwise, I can't reproduce the issue

Stranger6667 commented 4 months ago

Closing as I can't reproduce the reported issue with the recent library version.