sekineh: Hmm, I can't write utf-8 literal in test py files.
sekineh: In python2, `\w` seems to have different meaning than python3.
It seems regex is not a reliable method for sanitizing something.
sekineh: @willkg I think it's done.
Could you please review this?
sekineh: @willkg I added a commit to satisfy your request!
diff --git a/bleach/sanitizer.py b/bleach/sanitizer.py
index 79b80f5..6ccd78c 100644
--- a/bleach/sanitizer.py
+++ b/bleach/sanitizer.py
@@ -593,7 +593,8 @@ class BleachSanitizerFilter(html5lib_shim.SanitizerFilter):
         # the whole thing.
         parts = style.split(';')
         gauntlet = re.compile(
-            r"""^([-/:,#%.'"\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'\s*|"[\s\w]+"|\([\d,%\.\s]+\))*$"""
+            r"""^([-/:,#%.'"\s!\w]|\w-\w|'[\s\w]+'\s*|"[\s\w]+"|\([\d,%\.\s]+\))*$""",
+            flags=re.U
         )
 
         for part in parts:

Style filter does not work correctly when supplied non-ASCII style attribute
# Environment

Windows 10 Pro
Python 3.7.1
bleach         3.0.2

I've setup so that `color` style will survive after clean() method like below:
```
>>> bleach.clean('<span style="font-family:consolas;color:red">text</span>', tags = ['span'], attributes = {'span': ['style']}, styles = ['color'])
'<span style="color: red;">text</span>'
```

# Problem

When it contains non-ASCII style description such as Japanese font names, the `color` style is omitted.
```
>>> bleach.clean('<span style="font-family:メイリオ;color:red">text</span>', tags = ['span'], attributes = {'span': ['style']}, styles = ['color'])
'<span style="">text</span>'
```
It should retain the `color` style like below:
```
'<span style="color: red;">text</span>'
```
diff --git a/tests/test_css.py b/tests/test_css.py
index 12f27f3..7e34027 100644
--- a/tests/test_css.py
+++ b/tests/test_css.py
@@ -1,6 +1,8 @@
+# -*- coding: utf-8 -*-
 from functools import partial
 
 import pytest
+import six
 
 from bleach import clean
 
@@ -14,6 +16,11 @@ clean = partial(clean, tags=['p'], attributes=['style'])
         ['color'],
         'color: red;'
     ),
+    (
+        u'font-family: メイリオ; color: red; float: left; background-color: red;',
+        [u'color'],
+        u'color: red;'
+    ),
     (
         'border: 1px solid blue; color: red; float: left;',
         ['color'],
@@ -70,11 +77,19 @@ def test_allowed_css(data, styles, expected):
     p_double = "<p style='{0!s}'>bar</p>"
 
     if '"' in data:
+        if is_python2_unicode(data):
+            p_double = unicode(p_double)
         assert clean(p_double.format(data), styles=styles) == p_double.format(expected)
     else:
+        if is_python2_unicode(data):
+            p_single = unicode(p_single)
         assert clean(p_single.format(data), styles=styles) == p_single.format(expected)
 
 
+def is_python2_unicode(data):
+    return six.PY2 and isinstance(data, unicode)
+
+
 def test_valid_css():
     """The sanitizer should fix missing CSS values."""
     styles = ['color', 'float']

pip install -e '.[dev]'
parse_log_pytest
pytest
pytest
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/mozilla/bleach.git@2f210e06baacb1015bdde9896ad465dab0ccc378#egg=bleach
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
pytest @ file:///croot/pytest_1738938843180/work
six==1.17.0
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
webencodings==0.5.1

name: bleach
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - six==1.17.0
      - webencodings==0.5.1
prefix: /opt/conda/envs/bleach

tests/test_css.py::test_allowed_css[font-family:
tests/test_css.py::test_allowed_css[border: tests/test_css.py::test_allowed_css[color: tests/test_css.py::test_allowed_css[cursor: tests/test_css.py::test_allowed_css[text-overflow: tests/test_css.py::test_valid_css tests/test_css.py::test_urls[<p tests/test_css.py::test_style_hang tests/test_css.py::test_css_parsing_with_entities[<p
bleach/sanitizer.py
bleach/sanitizer.py