technosophos / querypath

QueryPath is a PHP library for manipulating XML and HTML. It is designed to work not only with local files, but also with web services and database resources.
http://querypath.org
Other
823 stars 115 forks source link

Upgrade from 2 to 3.0.3 - Found a bug? #146

Open vlinder opened 9 years ago

vlinder commented 9 years ago

I have found a weird case in the code when upgrading from 2 to version 3.0.3.

I solved it by accident by thinking I could save a line of code but shouldn't these two examples below be equivalent?

TEST1 was the code I had before and that worked with some version of 2. TEST2 is what I used to accidently solve my problem. And that works with version 3.

Shouldn't TEST1 work in version 3 too?

<?php
require_once 'vendor/autoload.php';

// TEST1

$qp1 = qp('<div></div>', 'div');

$qp1
    ->append('<p></p>')
    ->children() // First children...
    ->filter(':last-child') // ...and then filter
    ->append('text');

$test1 = $qp1->top()->find('body')->XHTML();

// TEST2

$qp2 = qp('<div></div>', 'div');

$qp2
    ->append('<p></p>')
    ->children(':last-child') // Children with filter
    ->append('text');

$test2 = $qp2->top()->find('body')->XHTML();

// RESULTS

echo ($test1 == $test2 ? 'Equal' : 'Not Equal') . PHP_EOL . PHP_EOL;

echo "TEST1:\n" . $test1 . PHP_EOL . PHP_EOL;
echo "TEST2:\n" . $test2 . PHP_EOL . PHP_EOL;
technosophos commented 9 years ago

At first glance, it does appear that TEST2 should work for QP3. I'll have to look into it. I know there was something wrong with filter(), but I think we fixed it.