Edgewall Software
Modify

Opened 21 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):  
    431431            if v is not None:
    432432                if k[-1:] == '_':
    433433                    k = k[:-1]
     434                if '_' in k:
     435                    k = k.replace('_', '-')
    434436                v = self._attr_value(k, v)
    435437                if v is not None:
    436438                    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)

comment:1 by Jun Omae, 20 months ago

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, however tag builder in Trac 1.4+ strips only one _ character.

$ script='from trac import __version__ as v
from trac.util.html import tag
print(v)
print(tag.a("anchor", class__="data:"))'
$ ~/venv/trac/1.0.20/bin/python -c "$script"
1.0.20
<a class="data:">anchor</a>
$ ~/venv/trac/1.4.3/bin/python -c "$script"
1.4.3
<a class_="data:">anchor</a>
$ ~/venv/trac/1.5.4/bin/python -c "$script"
1.5.4
<a class_="data:">anchor</a>
Last edited 20 months ago by Jun Omae (previous) (diff)

comment:2 by Ryan J Ollos, 14 months ago

Milestone: next-stable-1.4.xnext-stable-1.6.x

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.