Opened 17 years ago
Closed 17 years ago
#226 closed defect (fixed)
genshi Transformer Substitute Transformation performs replacement across the document instead of selected nodes
Reported by: | jhammel@… | Owned by: | cmlenz |
---|---|---|---|
Priority: | major | Milestone: | 0.5 |
Component: | General | Version: | devel |
Keywords: | Cc: |
Description
When doing a Transform(<xpath>).substitute(from, to) transformation, everything in the document that matches from is substituted instead of just elements matching the xpath expression:
>>> html2 <genshi.core.Stream object at 0xb7dba42c> >>> print html2 <b>foo</b><i>fee</i> >>> print html2 | Transformer('//b').replace('replaced') replaced<i>fee</i> >>> print html2 | Transformer('//b').substitute('f', 'g') <b>goo</b><i>gee</i>
Even though <i>fee</i> shouldn't be matched because it is not in the xpath (as evidenced by the preceding replace call), the substitution is erroneously performed.
I believe this is due to a missing check around here:
http://genshi.edgewall.org/browser/trunk/genshi/filters/transform.py#L871
I have fixed this locally by replacing this line with the following:
if kind is TEXT and mark is not None:
I'm not sure if this is a good fix, but it does get the above test example to correctly display:
>>> print html2 | Transformer('//b').substitute('f', 'g') <b>goo</b><i>fee</i>
Change History (1)
comment:1 Changed 17 years ago by athomas
- Resolution set to fixed
- Status changed from new to closed
Fixed in r852. Thanks jhammel!