GNOME Bugzilla – Bug 116841
zero-length prefix accepted, and validity error not raised
Last modified: 2009-08-15 18:40:50 UTC
Hi <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/SVG/DTD/svg10.dtd" > <svg xmlns:="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>foo</title> </svg> Note the colon after "xmlns" in line 6. It may be well-formed, but I don't think zero-length prefixes are legal. http://www.w3.org/TR/REC-xml-names/#ns-decl [2] PrefixedAttName ::= 'xmlns:' NCName http://www.w3.org/TR/REC-xml-names/#NT-NCName [4] NCName ::= (Letter | '_') (NCNameChar)* RXP http://www.cogsci.ed.ac.uk/~richard/rxp.html says (rxp -V -N -s -x):~ Warning: Undeclared attribute xmlns: for element svg in unnamed entity at line 6 char 9 of file:///C:/foo.txt Error: Attribute name xmlns: has empty local part in unnamed entity at line 6 char 9 of file:///C:/foo.txt Xerces: domcount foo.txt Error at file C:\foo.txt, line 6, char 10 Message: Attribute 'xmlns:' is not declared for element 'svg' domcount -n foo.txt Fatal Error at file C:\foo.txt, line 6, char 38 Message: When namespaces are enabled, the colon cannot be the first or last character xmllint, latest Window version libxml2-2.5.7.win32\util\xmllint xmllint --noout --valid --catalogs foo.txt => no error raised I think that xmllint should raise at least one of the errors that Xerces raises. If it's namespace-aware by default, then it should raise an error for a zero-length prefix (this would be raised even without the doctype declaration). And there is the invalidity error to be raised for the attribute which is illegal SVG 1.0. Tobi
Okay, right, that's a bad bug. It is now fixed in CVS: gnome:~/XML -> xmllint --noout tst.svg tst.svg:7: error: invalid namespace declaration 'xmlns:' xmlns:xlink="http://www.w3.org/1999/xlink"> ^ gnome:~/XML -> xmllint --noout --valid tst.svg tst.svg:7: error: invalid namespace declaration 'xmlns:' xmlns:xlink="http://www.w3.org/1999/xlink"> ^ tst.svg:7: validity error: No declaration for attribute xmlns: of element svg xmlns:xlink="http://www.w3.org/1999/xlink"> ^ gnome:~/XML -> thanks for the report ! Daniel
Happy to be of help :) Tobi
P.S. Regarding the error message: Would it be possible to list the line containing the error, not the one after it? eg xmlns:="http://www.w3.org/2000/svg" ^ not xmlns:xlink="http://www.w3.org/1999/xlink"> ^ Tobi
Unfortunately no. The line number can only be associated to an element, and the error is only caught at the SAX callback level i.e. after the whole element start has been parsed, so no that would be quite hard to achieve. Daniel
I see, but then people don't see the erratic code when looking at the error message. Perhaps you could list the whole element? eg [...] error: invalid namespace declaration 'xmlns:' <svg xmlns:="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> [...] validity error: No declaration for attribute xmlns: of element svg <svg xmlns:="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> Tobi
Even that is impossible in general, the string for the beginning of the element my not even be available in memory anymore. All I can provide is a limited set of characters on the last line. Yes this is a performance trade-off. Daniel
This should be closed by release of libxml2-2.5.9, thanks, Daniel