Skip to content

Commit 173f205

Browse files
committed
fixed GH# 128: DOMWriter incorrectly adds SYSTEM keyword to DTD if PUBLIC is already specified
1 parent e6a24b3 commit 173f205

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

XML/src/XMLWriter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,11 @@ void XMLWriter::startDTD(const XMLString& name, const XMLString& publicId, const
493493
}
494494
if (!systemId.empty())
495495
{
496-
writeMarkup(" SYSTEM \"");
496+
if (publicId.empty())
497+
{
498+
writeMarkup(" SYSTEM");
499+
}
500+
writeMarkup(" \"");
497501
writeXML(systemId);
498502
writeMarkup("\"");
499503
}

XML/testsuite/src/XMLWriterTest.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// XMLWriterTest.cpp
33
//
4-
// $Id: //poco/1.4/XML/testsuite/src/XMLWriterTest.cpp#3 $
4+
// $Id: //poco/1.4/XML/testsuite/src/XMLWriterTest.cpp#4 $
55
//
66
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
77
// and Contributors.
@@ -169,6 +169,24 @@ void XMLWriterTest::testDTD()
169169
}
170170

171171

172+
void XMLWriterTest::testDTDPublic()
173+
{
174+
std::ostringstream str;
175+
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION);
176+
writer.setNewLine("\n");
177+
writer.startDocument();
178+
writer.startDTD("test", "test", "http://www.appinf.com/DTDs/test");
179+
writer.endDTD();
180+
writer.startElement("", "", "foo");
181+
writer.endElement("", "", "foo");
182+
writer.endDocument();
183+
std::string xml = str.str();
184+
assert (xml == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
185+
"<!DOCTYPE test PUBLIC \"test\" \"http://www.appinf.com/DTDs/test\">"
186+
"<foo/>");
187+
}
188+
189+
172190
void XMLWriterTest::testDTDNotation()
173191
{
174192
std::ostringstream str;
@@ -621,6 +639,7 @@ CppUnit::Test* XMLWriterTest::suite()
621639
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragmentPretty);
622640
CppUnit_addTest(pSuite, XMLWriterTest, testDTDPretty);
623641
CppUnit_addTest(pSuite, XMLWriterTest, testDTD);
642+
CppUnit_addTest(pSuite, XMLWriterTest, testDTDPublic);
624643
CppUnit_addTest(pSuite, XMLWriterTest, testDTDNotation);
625644
CppUnit_addTest(pSuite, XMLWriterTest, testDTDEntity);
626645
CppUnit_addTest(pSuite, XMLWriterTest, testAttributes);

XML/testsuite/src/XMLWriterTest.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// XMLWriterTest.h
33
//
4-
// $Id: //poco/1.4/XML/testsuite/src/XMLWriterTest.h#1 $
4+
// $Id: //poco/1.4/XML/testsuite/src/XMLWriterTest.h#2 $
55
//
66
// Definition of the XMLWriterTest class.
77
//
@@ -54,6 +54,7 @@ class XMLWriterTest: public CppUnit::TestCase
5454
void testTrivialFragmentPretty();
5555
void testDTDPretty();
5656
void testDTD();
57+
void testDTDPublic();
5758
void testDTDNotation();
5859
void testDTDEntity();
5960
void testAttributes();

0 commit comments

Comments
 (0)