Modify ↓
Opened 20 months ago
Last modified 14 months ago
#13579 new defect
Element factory doesn't convert underscores to hyphens for keyword arguments
Reported by: | Jun Omae | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | next-stable-1.6.x |
Component: | general | Version: | 1.4 |
Severity: | minor | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
$ script='from trac import __version__ as v; from trac.util.html import tag ; print(v); print(tag.span("", data_name="value"))' $ ~/venv/trac/1.0.20/bin/python -c "$script" 1.0.20 <span data-name="value"></span> $ ~/venv/trac/1.4.3/bin/python -c "$script" 1.4.3 <span data_name="value"></span> $ ~/venv/trac/1.5.4/bin/python -c "$script" 1.5.4 <span data_name="value"></span>
Patch:
-
trac/util/html.py
diff --git a/trac/util/html.py b/trac/util/html.py index 600c30b98..a1230fcd0 100644
a b class XMLElement(Fragment): 431 431 if v is not None: 432 432 if k[-1:] == '_': 433 433 k = k[:-1] 434 if '_' in k: 435 k = k.replace('_', '-') 434 436 v = self._attr_value(k, v) 435 437 if v is not None: 436 438 attrs.append((k, escape(v)))
Workaround is passing a dict with names converted to hyphens:
$ script='from trac import __version__ as v; from trac.util.html import tag ; print(v); print(tag.span("", **{"data-name": "value"}))' $ ~/venv/trac/1.0.20/bin/python -c "$script" 1.0.20 <span data-name="value"></span> $ ~/venv/trac/1.4.3/bin/python -c "$script" 1.4.3 <span data-name="value"></span> $ ~/venv/trac/1.5.4/bin/python -c "$script" 1.5.4 <span data-name="value"></span>
Attachments (0)
Change History (2)
Note:
See TracTickets
for help on using tickets.
I noticed another incompatible behavior with Genshi builder, while reading https://github.com/edgewall/genshi/blob/0.7.7/genshi/builder.py#L159-L163.
Genshi builder strips all trailing
_
characters from attribute names, howevertag
builder in Trac 1.4+ strips only one_
character.