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
Change-Id: I0ad38b9741d760f1ce688a36f969ec14e20a928c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 366bdcde97962cf5804c519e9b605eddb543a592)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Vincent Baijot 2021-04-18 18:23:46 +02:00 committed by Qt Cherry-pick Bot
parent c701e6bb38
commit ff9a091241
10 changed files with 17 additions and 13 deletions

View File

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

View File

@ -92,6 +92,7 @@ bool QXmlStreamReaderPrivate::parse()
setType(QXmlStreamReader::EndElement); setType(QXmlStreamReader::EndElement);
Tag tag = tagStack_pop(); Tag tag = tagStack_pop();
namespaceUri = tag.namespaceDeclaration.namespaceUri; namespaceUri = tag.namespaceDeclaration.namespaceUri;
prefix = tag.namespaceDeclaration.prefix;
name = tag.name; name = tag.name;
qualifiedName = tag.qualifiedName; qualifiedName = tag.qualifiedName;
isEmptyElement = false; isEmptyElement = false;
@ -843,6 +844,7 @@ bool QXmlStreamReaderPrivate::parse()
Tag tag = tagStack_pop(); Tag tag = tagStack_pop();
namespaceUri = tag.namespaceDeclaration.namespaceUri; namespaceUri = tag.namespaceDeclaration.namespaceUri;
prefix = tag.namespaceDeclaration.prefix;
name = tag.name; name = tag.name;
qualifiedName = tag.qualifiedName; qualifiedName = tag.qualifiedName;
if (qualifiedName != symName(3)) 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" StartElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" prefix="a"
NamespaceDeclaration( prefix="a" namespaceUri="http://example.org/namespace" ) 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( ) EndDocument( )

View File

@ -8,8 +8,8 @@ Characters( whitespace text="
StartElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" prefix="a" StartElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" prefix="a"
NamespaceDeclaration( prefix="a" namespaceUri="http://example.org/other-namespace" ) 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=" 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( ) EndDocument( )

View File

@ -16,7 +16,7 @@ StartElement( name="bar" namespaceUri="http://example.org/~kipper" qualifiedName
Attribute( name="attr" qualifiedName="attr" value="2" ) 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=" 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" ) 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=" Characters( whitespace text="
" ) " )

View File

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

View File

@ -5,5 +5,5 @@ StartElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" pref
NamespaceDeclaration( prefix="ns" namespaceUri="namespaceUri" ) NamespaceDeclaration( prefix="ns" namespaceUri="namespaceUri" )
) )
Characters( text="The world goes round and round" ) 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( ) 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" ) StartElement( name="title" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:title" prefix="html" )
Characters( text="test file" ) 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=" 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=" Characters( whitespace text="
" ) " )
StartElement( name="body" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:body" prefix="html" ) 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" ) Attribute( name="class" qualifiedName="class" value="visible:false" )
) )
Characters( text="bar" ) 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=" 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=" 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( ) EndDocument( )

View File

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