Correct prefix reported for end element in QXmlStreamReader

Before this change, QXmlStreamReader prefix value was always an empty
string for EndElement when the documentation state : "Returns the prefix
of a StartElement or EndElement."

The error was a missing update of the prefix value when parsing
EndElement.

I updated the tests data which were also wrong because no prefix were
reported even for </a:foo>. No new test is necessary, I think, the test
data already cover the cases of EndElement with a prefix and without one
(unchanged here).

Fixes: QTBUG-86847
Pick-to: 5.15 6.0 6.1
Change-Id: I0ad38b9741d760f1ce688a36f969ec14e20a928c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Vincent Baijot 2021-04-18 18:23:46 +02:00
parent 3bb523eb66
commit 366bdcde97
10 changed files with 17 additions and 13 deletions

View File

@ -237,6 +237,7 @@ bool QXmlStreamReaderPrivate::parse()
setType(QXmlStreamReader::EndElement);
Tag tag = tagStack_pop();
namespaceUri = tag.namespaceDeclaration.namespaceUri;
prefix = tag.namespaceDeclaration.prefix;
name = tag.name;
qualifiedName = tag.qualifiedName;
isEmptyElement = false;
@ -1300,6 +1301,7 @@ etag ::= LANGLE SLASH qname space_opt RANGLE;
namespaceUri = tag.namespaceDeclaration.namespaceUri;
name = tag.name;
qualifiedName = tag.qualifiedName;
prefix = tag.namespaceDeclaration.prefix;
if (qualifiedName != symName(3))
raiseWellFormedError(QXmlStream::tr("Opening and ending tag mismatch."));
} break;

View File

@ -92,6 +92,7 @@ bool QXmlStreamReaderPrivate::parse()
setType(QXmlStreamReader::EndElement);
Tag tag = tagStack_pop();
namespaceUri = tag.namespaceDeclaration.namespaceUri;
prefix = tag.namespaceDeclaration.prefix;
name = tag.name;
qualifiedName = tag.qualifiedName;
isEmptyElement = false;
@ -843,6 +844,7 @@ bool QXmlStreamReaderPrivate::parse()
Tag tag = tagStack_pop();
namespaceUri = tag.namespaceDeclaration.namespaceUri;
prefix = tag.namespaceDeclaration.prefix;
name = tag.name;
qualifiedName = tag.qualifiedName;
if (qualifiedName != symName(3))

View File

@ -3,5 +3,5 @@ Comment( text=" Simple legal case: prefixed element " )
StartElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" prefix="a"
NamespaceDeclaration( prefix="a" namespaceUri="http://example.org/namespace" )
)
EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" )
EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" prefix="a" )
EndDocument( )

View File

@ -8,8 +8,8 @@ Characters( whitespace text="
StartElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" prefix="a"
NamespaceDeclaration( prefix="a" namespaceUri="http://example.org/other-namespace" )
)
EndElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" )
EndElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" prefix="a" )
Characters( whitespace text="
" )
EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" )
EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" prefix="a" )
EndDocument( )

View File

@ -16,7 +16,7 @@ StartElement( name="bar" namespaceUri="http://example.org/~kipper" qualifiedName
Attribute( name="attr" qualifiedName="attr" value="2" )
)
EndElement( name="bar" namespaceUri="http://example.org/~kipper" qualifiedName="b:bar" )
EndElement( name="bar" namespaceUri="http://example.org/~kipper" qualifiedName="b:bar" prefix="b" )
Characters( whitespace text="
" )

View File

@ -12,7 +12,7 @@ StartElement( name="bar" namespaceUri="http://example.org/~wilbur" qualifiedName
Attribute( name="attr" qualifiedName="attr" value="2" )
)
EndElement( name="bar" namespaceUri="http://example.org/~wilbur" qualifiedName="a:bar" )
EndElement( name="bar" namespaceUri="http://example.org/~wilbur" qualifiedName="a:bar" prefix="a" )
Characters( whitespace text="
" )

View File

@ -4,5 +4,5 @@ StartElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" pref
NamespaceDeclaration( prefix="ns" namespaceUri="namespaceUri" )
)
EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" )
EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" prefix="ns" )
EndDocument( )

View File

@ -5,5 +5,5 @@ StartElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" pref
NamespaceDeclaration( prefix="ns" namespaceUri="namespaceUri" )
)
Characters( text="The world goes round and round" )
EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" )
EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" prefix="ns" )
EndDocument( )

View File

@ -33,10 +33,10 @@ Characters( whitespace text="
" )
StartElement( name="title" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:title" prefix="html" )
Characters( text="test file" )
EndElement( name="title" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:title" )
EndElement( name="title" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:title" prefix="html" )
Characters( whitespace text="
" )
EndElement( name="head" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:head" )
EndElement( name="head" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:head" prefix="html" )
Characters( whitespace text="
" )
StartElement( name="body" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:body" prefix="html" )
@ -46,11 +46,11 @@ StartElement( name="p" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName
Attribute( name="class" qualifiedName="class" value="visible:false" )
)
Characters( text="bar" )
EndElement( name="p" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:p" )
EndElement( name="p" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:p" prefix="html" )
Characters( whitespace text="
" )
EndElement( name="body" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:body" )
EndElement( name="body" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:body" prefix="html" )
Characters( whitespace text="
" )
EndElement( name="html" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:html" )
EndElement( name="html" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:html" prefix="html" )
EndDocument( )

View File

@ -15,7 +15,7 @@ Characters( whitespace text="
StartElement( name="bar" namespaceUri="http://qt-project.org" qualifiedName="pre:bar" prefix="pre"
NamespaceDeclaration( prefix="pre" namespaceUri="http://qt-project.org" )
)
EndElement( name="bar" namespaceUri="http://qt-project.org" qualifiedName="pre:bar" )
EndElement( name="bar" namespaceUri="http://qt-project.org" qualifiedName="pre:bar" prefix="pre" )
Characters( whitespace text="
" )
EndElement( name="body" qualifiedName="body" )