Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kdwsdl2cpp: Avoid potential type collisions in nested complexTypes #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions kdwsdl2cpp/schema/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,13 @@ Element Parser::parseElement(ParserContext *context,
//qDebug() << "childName:" << childName.localName();
if (childName.localName() == QLatin1String("complexType")) {
ComplexType ct = parseComplexType(context, childElement);

ct.setName(newElement.name());
QString name = newElement.name();
int i = 0;
while (!d->mComplexTypes.complexType(QName(ct.nameSpace(), name)).name().isEmpty())
name = newElement.name() + QString::number(++i);
if (name != newElement.name() && debugParsing())
qDebug() << " detected potential type collision in nested complexType, updated name" << newElement.name() << "to" << name;
ct.setName(name);
ct.setAnonymous(true);
d->mComplexTypes.append(ct);

Expand Down
14 changes: 14 additions & 0 deletions unittests/wsdl_document/mywsdl_document.wsdl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<sequence>
<element name="TelegramHex" type="kdab:TelegramType"/>
<element name="TelegramBase64" type="xsd:base64Binary"/>
<xsd:element name="repeatedName">
<complexType>
<sequence>
<element name='stringparam1' type='xsd:string'/>
</sequence>
</complexType>
</xsd:element>
</sequence>
</complexType>
</element>
Expand Down Expand Up @@ -137,6 +144,13 @@
<sequence>
<element name='employeeName' type='kdab:EmployeeName'/>
<element name='repeatedChildren' type='kdab:TestRepeatedChildren'/>
<xsd:element name="repeatedName">
<complexType>
<sequence>
<element name='intparam1' type='xsd:int'/>
</sequence>
</complexType>
</xsd:element>
</sequence>
</complexType>
</element>
Expand Down
19 changes: 19 additions & 0 deletions unittests/wsdl_document/test_wsdl_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,23 @@ private Q_SLOTS:
params.setRepeatedChildren(children);
}

// Test repeated names in nested complex types
void testRepeatedNames()
{
// Just test the generated code, two different classes should have been
// created for two structurally different nested complex types of the
// same name:
KDAB__TelegramResponse resp;
class KDAB__RepeatedName repeatedName;
repeatedName.setStringparam1("test1");
resp.setRepeatedName(repeatedName);

KDAB__EmployeeNameParams params;
class KDAB__RepeatedName1 repeatedName1;
repeatedName1.setIntparam1(1);
params.setRepeatedName(repeatedName1);
}

void testSoapVersion()
{
// Prepare response
Expand Down Expand Up @@ -714,6 +731,7 @@ public slots:
"David Ä Faure"
"</n1:employeeName>"
"<n1:repeatedChildren><n1:low>0</n1:low><n1:width>0</n1:width><n1:center>0</n1:center></n1:repeatedChildren>"
"<n1:repeatedName><n1:intparam1>0</n1:intparam1></n1:repeatedName>"
"</n1:EmployeeNameParams>"
"</soap:Body>" + xmlEnvEnd()
+ '\n'; // added by QXmlStreamWriter::writeEndDocument
Expand Down Expand Up @@ -1068,6 +1086,7 @@ void WsdlDocumentTest::testSendTelegram()
QByteArray(xmlBegin) + "<n1:TelegramResponse " + xmlNamespaces + " xmlns:n1=\"http://www.kdab.com/xml/MyWsdl/\">"
"<n1:TelegramHex>52656365697665642048656c6c6f</n1:TelegramHex>"
"<n1:TelegramBase64>UmVjZWl2ZWQgSGVsbG8=</n1:TelegramBase64>"
"<n1:repeatedName><n1:stringparam1></n1:stringparam1></n1:repeatedName>"
"</n1:TelegramResponse>";
// m_response, however, has qualified = true (set by the generated code).
QVERIFY(xmlBufferCompare(server->lastServerObject()->m_response.toXml(KDSoapValue::LiteralUse, msgNS), expectedResponseXml));
Expand Down