Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r92811:df15dab6a182
Date: 2017-10-20 21:36 +0200
http://bitbucket.org/pypy/pypy/changeset/df15dab6a182/
Log: Issue2684: pyexpat.CreateParser() did not handle correctly
namespace_separator=""
diff --git a/pypy/module/pyexpat/interp_pyexpat.py
b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -808,7 +808,7 @@
w_encoding)
if space.is_none(w_namespace_separator):
- namespace_separator = 0
+ namespace_separator = -1
elif space.isinstance_w(w_namespace_separator, space.w_text):
separator = space.text_w(w_namespace_separator)
if len(separator) == 0:
@@ -831,7 +831,7 @@
elif space.is_w(w_intern, space.w_None):
w_intern = None
- if namespace_separator:
+ if namespace_separator >= 0:
xmlparser = XML_ParserCreateNS(
encoding,
rffi.cast(rffi.CHAR, namespace_separator))
diff --git a/pypy/module/pyexpat/test/test_parser.py
b/pypy/module/pyexpat/test/test_parser.py
--- a/pypy/module/pyexpat/test/test_parser.py
+++ b/pypy/module/pyexpat/test/test_parser.py
@@ -59,7 +59,7 @@
p.CharacterDataHandler = lambda s: data.append(s)
encoding = encoding_arg is None and 'utf-8' or encoding_arg
- res = p.Parse(u"<xml>\u00f6</xml>".encode(encoding),
isfinal=True)
+ res = p.Parse(u"<xml>\u00f6</xml>".encode(encoding), True)
assert res == 1
assert data == [u"\u00f6"]
@@ -188,6 +188,34 @@
p.ParseFile(fake_reader)
assert fake_reader.read_count == 4
+ def test_entities(self):
+ import pyexpat
+ parser = pyexpat.ParserCreate(None, "")
+
+ def startElement(tag, attrs):
+ assert tag == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#RDF'
+ assert attrs == {
+ 'http://www.w3.org/XML/1998/namespacebase':
+ 'http://www.semanticweb.org/jiba/ontologies/2017/0/test'}
+ parser.StartElementHandler = startElement
+ parser.Parse("""<?xml version="1.0"?>
+
+ <!DOCTYPE rdf:RDF [
+ <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
+ <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
+ <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
+ <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
+ ]>
+
+ <rdf:RDF
xmlns="http://www.semanticweb.org/jiba/ontologies/2017/0/test#"
+ xml:base="http://www.semanticweb.org/jiba/ontologies/2017/0/test"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ </rdf:RDF>
+ """, True)
+
class AppTestPyexpat2:
spaceconfig = dict(usemodules=['pyexpat', 'itertools', '_socket',
'time', 'struct', 'binascii'])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit