Commits

Anonymous committed 35e608b

Fix empty html bug. For example, the following behavior is as expected:
>>> S = PyQuery('<p>Hello world</p>')
>>> S('<div>Test</div>').text()
'Test'

but:
>>> S('').text()
'Hello world'

This commit fixed that.

Comments (0)

Files changed (2)

pyquery/pyquery.py

         length = len(args)
         if length == 0:
             raise ValueError('You must provide at least a selector')
+        if args[0] == '':
+            return self.__class__([])
         if len(args) == 1 and isinstance(args[0], str) and not args[0].startswith('<'):
             args += (self,)
         result = self.__class__(*args, **dict(parent=self))
         assert len(e(":parent")) == 2
         assert len(e(":empty")) == 6
         assert len(e(":contains('Heading')")) == 6
+        
+    def test_on_the_fly_dom_creation(self):
+        e = self.klass(self.html)
+        assert e('<p>Hello world</p>').text() == 'Hello world'
+        assert e('').text() == None
 
 class TestTraversal(unittest.TestCase):
     klass = pq