ZF-10856: Zend_Dom_Query problem with css selector which contains dots in attribute selector

Issue Type: Bug Created: 2010-12-20T11:13:35.000+0000 Last Updated: 2012-11-20T21:37:36.000+0000 Status: Open Fix version(s): Reporter: Sasa Stamenkovic (umpirsky) Assignee: None Tags: - Zend_Dom_Query

Related issues: Attachments:


Lets have xml file like this and try to do this, we get error "Fatal error: Call to a member function item() on a non-object in Zend\Dom\Query\Result.php on line 150".

Generated Xpath query is //tv//programme[@channel='cnn[contains(concat(' ', normalize-space(@class), ' '), ' tv ')][contains(concat(' ', normalize-space(@class), ' '), ' gonix ')][contains(concat(' ', normalize-space(@class), ' '), ' net ')]'].

With Xpath query '//tv//programme[@channel=""]' ($query->queryXpath()) it works perfect.

Here is the unit test to use with file

Index: D:/Libraries/ZendFramework/svn/tests/Zend/Dom/QueryTest.php

--- D:/Libraries/ZendFramework/svn/tests/Zend/Dom/QueryTest.php (revision 23462) +++ D:/Libraries/ZendFramework/svn/tests/Zend/Dom/QueryTest.php (working copy) @@ -311,6 +311,15 @@ $this->assertType('DOMDocument', $doc); $this->assertEquals('utf-8', $doc->encoding); } +

  • public function testAttributeDotCssSelectorOnXmlDocument() + { + $file = file_get_contents(dirname(FILE) . '/_files/xml.xml'); + $this->query->setDocument($file); + $result = $this->query->query('tv programme[channel=""]'); + $this->assertEqual($result->count(), 3); + $this->assertEqual($result->current()->getElementsByTagName('title')->item(0)->nodeValue, 'Connect the World with Becky Anderson'); + } }

// Call Zend_Dom_QueryTest::main() if this source file is executed directly.


Posted by Matthew Weier O'Phinney (matthew) on 2010-12-20T11:26:18.000+0000

I'll see what I can do. Likely, however, the only way to address this would be to write a full CSS selector parser -- the current incarnation is not at all context-aware and relies heavily on fast operations such as str_replace().

Posted by Sasa Stamenkovic (umpirsky) on 2010-12-20T12:23:09.000+0000

There is… which have cssToXpath(). This component is a port of the Python lxml library, which is copyright Infrae and distributed under the BSD license. Didn't try this, but if it works, maybe sth can be learned from there.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.