-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parser stucked in loop #87
Comments
This is not going to work well, because by the time you call read or next, you might actually be deeper inside the xml document. Calling next will also traverse beyond Could you share the xml snippet you are trying to parse, and what PHP data structure you wish to get? I might be able to rewrite it in a way where it's a lot clearer. Ideally you should never really have to do manual traversal like this, unless it's a special circumstance. |
I will try to share you only the peace of xml that is wrong.
I use your reader like in the documentation. I just go deeper in the code and found this loop ; i tried to "debug it", tyring to "force" the reader to find the next element. I don't use this loop myself ^^ When my element is parsed, it go an error, but you silence it (https://github.com/fruux/sabre-xml/blob/master/lib/Reader.php#L145); Anyway, I will paste you a complete example =) |
The error is indeed silenced there, but the error does get stored and we actually take it out here again: https://github.com/fruux/sabre-xml/blob/master/lib/Reader.php#L151 There might be a bug in the error handling code though. The error you shared definitely seems to indicate so. So it would then be extra awesome to get a snippet of your xml that reproduces this, so we can make the parser more robust =) |
Hi @Gounlaf , I received your data via email. Thanks very much for that. I tried to reproduce the issue with the following script: <?php
include 'vendor/autoload.php';
$reader = new Sabre\Xml\Reader();
$reader->open('xml_bug_wrong_encoding.xml');
var_dump($reader->parse()); This causes an exception to be triggered immediately:
I would consider this the expected behavior. Are you also seeing this when you run my test script or do you get the loop? |
The problem with your file BTW is that ASCII character 26 (1A) appears in your source. This encodes CTRL-Z and should normally never appear in a text file. But still it shouldn't go in a never-ending loop |
Hi @evert, But if i use the example given in "http://sabre.io/xml/reading/ => Using the XmlDeserializable interface", there is the loop. I sent you the "looping example" by email. |
Would it be possible for you to email me a script that always reproduces the error. It's a bit hard for me to figure out where this is going wrong. The example you mention on sabre.io should be fine because it just uses So ideally if you could send me a single php file that has a minimal sample that reproduces the problem for you, I would be very grateful! |
Hi @evert , I did yesterday, with the data I already sent to you, and the "copy/past" of the example, adapted for the data. Anyway, you can find it bellow :) <?php
include 'vendor/autoload.php';
class Offers implements Sabre\Xml\XmlDeserializable
{
public $data = array();
static function xmlDeserialize(Sabre\Xml\Reader $reader) {
$offers = new self();
$children = $reader->parseInnerTree();
foreach($children as $child) {
if ($child['value'] instanceof Offer) {
$offers->data[] = $child['value'];
}
}
return $offers;
}
}
class Offer implements Sabre\Xml\XmlDeserializable {
static function xmlDeserialize(Sabre\Xml\Reader $reader) {
$offer = new self();
// Borrowing a parser from the KeyValue class.
$keyValue = Sabre\Xml\Element\KeyValue::xmlDeserialize($reader);
// if (isset($keyValue['{http://example.org/books}title'])) {
// $book->title = $keyValue['{http://example.org/books}title'];
// }
// if (isset($keyValue['{http://example.org/books}author'])) {
// $book->author = $keyValue['{http://example.org/books}author'];
// }
return $offer;
}
}
$reader = new Sabre\Xml\Reader();
$reader->elementMap = [
'{}offres' => 'Offers',
'{}offre' => 'Offer',
];
$reader->open('xml_bug_wrong_encoding.xml');
var_dump($reader->parse()); |
I'm closing this ticket because it's been a while since the last comment. If this is indeed still an issue, feel free to comment here so we can continue discussing. This is just a general cleanup. And unfortunately this ticket never got a fully working sample. Might have gotten it via email back in february, but I no longer have it. If you care about this ticket still, please submit the info again (preferably just on github). |
Hi,
I have an XML input with encoding problems.
I use the default KeyValue element ;
Because of the encoding problem, the function "keyValue" is strucked in the loop ; the reader object never reach the node "Reader::END_ELEMENT".
I've tried both :
It doesn't work, reader styled stucked on the same element =/
Any idea/way to skip element and move further ?
Thanks,
Regards
The text was updated successfully, but these errors were encountered: