Edgewall Software

Changeset 1269 for trunk/genshi


Ignore:
Timestamp:
Mar 20, 2014, 1:58:48 PM (10 years ago)
Author:
hodgestar
Message:

Return correct value and properly namespaced attribute name when matching namespaced attributes with XPath expressions (fixes #572; thanks to Olemis Lang <olemis+trac@…> for bug report and suggestion for fix).

Location:
trunk/genshi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/genshi/path.py

    r1083 r1269  
    10091009        if kind is START:
    10101010            if self.principal_type is ATTRIBUTE and qname in data[1]:
    1011                 return Attrs([(self.name, data[1].get(self.name))])
     1011                return Attrs([(qname, data[1].get(qname))])
    10121012            else:
    10131013                return data[0] == qname
  • trunk/genshi/tests/path.py

    r1087 r1269  
    1515import unittest
    1616
     17from genshi.core import Attrs, QName
    1718from genshi.input import XML
    1819from genshi.path import Path, PathParser, PathSyntaxError, GenericStrategy, \
     
    631632                              output='')
    632633
     634    def test_attr_selection(self):
     635        xml = XML('<root><foo bar="abc"></foo></root>')
     636        path = Path('foo/@bar')
     637        result = path.select(xml)
     638        self.assertEqual(list(result), [
     639            Attrs([(QName('bar'), u'abc')])
     640        ])
     641
     642    def test_attr_selection_with_namespace(self):
     643        xml = XML(
     644            '<root xmlns:ns1="http://example.com">'
     645            '<foo ns1:bar="abc"></foo>'
     646            '</root>')
     647        path = Path('foo/@ns1:bar')
     648        result = path.select(xml, namespaces={'ns1': 'http://example.com'})
     649        self.assertEqual(list(result), [
     650            Attrs([(QName('http://example.com}bar'), u'abc')])
     651        ])
     652
    633653    def _test_support(self, strategy_class, text):
    634654        path = PathParser(text, None, -1).parse()[0]
Note: See TracChangeset for help on using the changeset viewer.