Home » File Formats » File_XSPF » Bug #6696
critical error with parsing an xspf playlist in string format
Details
| Submitted | 2006-02-05 13:23 UTC |
|---|---|
| From | spam at electroteque dot org |
| Assigned | djg |
| Status | Closed |
| Package | File_XSPF |
| PHP Version | 5.1.1 |
| OS | n/a |
| Roadmaps | (Not assigned) |
Comments
[2006-02-05 13:23 UTC] spam at electroteque dot org
Description:
------------
Hi i found your new method for parsing xspf playlists in
string format however there is a critical bug in the xml
parser, you may have to change the method from setInput
to setInputString, here is the issue, file_exists is
returning true in php 5.1.2, when its in fact a string,
i guess this is a bug in xml parser but i guess you
should prob use setInputString instead ??
function setInput($fp)
{
if (is_resource($fp)) {
$this->fp = $fp;
return true;
}
// see if it's an absolute URL (has a scheme at
the beginning)
elseif (eregi('^[a-z]+://', substr($fp, 0, 10)))
{
return $this->setInputFile($fp);
}
// see if it's a local file
elseif (file_exists($fp)) {
die("yes");
return $this->setInputFile($fp);
}
// it must be a string
else {
die("yes");
$this->fp = $fp;
return true;
}
return $this->raiseError('Illegal input format',
XML_PARSER_ERROR_INVALID_INPUT);
}
Test script:
---------------
Just to confirm this works fine, somehow it had stopped working when i made the upgrade in php 5.1.2 i think, maybe this is also a bug in php 5.1.2 ?? Ill ask the list.
function parse($text) {
$parser =& new XML_Parser();
$handle =& new File_XSPF_Handler($this);
$result = $parser->setInputString($text);
if (PEAR::isError($result)) {
return PEAR::raiseError($result->getMessage(), $result->getCode());
}
$parser->setHandlerObj($handle);
$result = $parser->parse();
if (PEAR::isError($result)) {
return PEAR::raiseError($result->getMessage(), $result->getCode());
}
if (PEAR::isError($this->_parse_error)) {
return PEAR::raiseError($this->_parse_error->getMessage(), $this->_parse_error->getCode());
}
return true;
}
[2006-02-05 15:40 UTC] spam at electroteque dot org
Sorry to reproduce the error
$data = "<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>electroteque's Recent Tracks</title>
<creator>Audioscrobbler</creator>
<info>http://www.last.fm/user/electroteque/</info>
<license>http://creativecommons.org/licenses/by-nc-sa/
2.0/uk/</license>
<trackList>
<track>
<title>Sleepy Mimer</title>
<creator>electroteque</creator>
<info>http://www.last.fm/music/electroteque/_/
Sleepy+Mimer</info>
</track>
<track>
<title>Looking for Sophie</title>
<creator>doc</creator>
<info>http://www.last.fm/music/doc/_/
Looking+for+Sophie</info>
</track>
<track>
<title>Norkhaberg</title>
<creator>KraftiM</creator>
<info>http://www.last.fm/music/KraftiM/_/
Norkhaberg</info>
</track>
<track>
<title>Nocturnal Nail Clipping</title>
<creator>frags</creator>
<info>http://www.last.fm/music/frags/_/
Nocturnal+Nail+Clipping</info>
</track>
<track>
<title>Climate Changes</title>
<creator>electroteque</creator>
<info>http://www.last.fm/music/electroteque/_/
Climate+Changes</info>
</track>
<track>
<title>Tre Komma Fem Procent</title>
<creator>Unknown Forces</creator>
<info>http://www.last.fm/music/Unknown+Forces/_/
Tre+Komma+Fem+Procent</info>
</track>
<track>
<title>Airports for Music</title>
<creator>doc</creator>
<info>http://www.last.fm/music/doc/_/
Airports+for+Music</info>
</track>
<track>
<title>Mayfirst</title>
<creator>Move D</creator>
<info>http://www.last.fm/music/Move+D/_/Mayfirst</
info>
<duration>486000</duration>
</track>
</trackList>
</playlist>";
@require_once "File/XSPF.php";
$xspf = new File_XSPF();
$xspf->parse($data);
return $xspf->getTracks();
[2006-02-06 13:20 UTC] djg at php dot net
[2006-02-06 13:22 UTC] djg at php dot net
[2006-02-06 13:23 UTC] djg at php dot net
Fixed in CVS.