Skip to content

Commit c4ff236

Browse files
committed
Fixed a bug in XMLParser that was not configuring the DTD file path correctly
1 parent 717788f commit c4ff236

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

libs/libparsers/src/xmlparser.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,19 @@ void XmlParser::setDTDFile(const QString &dtd_file, const QString &dtd_name)
127127
throw Exception(ErrorCode::AsgEmptyDTDName,__PRETTY_FUNCTION__,__FILE__,__LINE__);
128128

129129
#ifndef Q_OS_WIN
130-
fmt_dtd_file="file://";
130+
fmt_dtd_file = "file://";
131131
#else
132-
fmt_dtd_file="file:///";
132+
fmt_dtd_file = "file:///";
133133
#endif
134134

135135
//Formats the dtd file path to URL style (converting to percentage format the non reserved chars)
136-
fmt_dtd_file=QUrl::toPercentEncoding(QFileInfo(dtd_file).absoluteFilePath(), "/:");
137-
dtd_decl="<!DOCTYPE " + dtd_name +
138-
" SYSTEM " + "\"" + fmt_dtd_file + "\">\n";
136+
fmt_dtd_file += QUrl::toPercentEncoding(QFileInfo(dtd_file).absoluteFilePath(), "/:");
137+
dtd_decl = "<!DOCTYPE " + dtd_name + " SYSTEM " + "\"" + fmt_dtd_file + "\">\n";
139138
}
140139

141140
void XmlParser::readBuffer()
142141
{
143142
QByteArray buffer;
144-
QString msg, file;
145143
int parser_opt;
146144

147145
if(!xml_buffer.isEmpty())
@@ -173,19 +171,28 @@ void XmlParser::readBuffer()
173171
//If some error is set
174172
if(xml_error)
175173
{
174+
QString msg, file, extra_info {
175+
QString(QT_TR_NOOP("XML file: %1")).arg(xml_doc_filename) + "\n" +
176+
QString(QT_TR_NOOP("DTD decl: %1")).arg(dtd_decl) };
177+
176178
//Formats the error
177-
msg=xml_error->message;
178-
file=xml_error->file;
179-
if(!file.isEmpty()) file=QString("(%1)").arg(file);
179+
msg = xml_error->message;
180+
file = xml_error->file;
181+
182+
if(!file.isEmpty())
183+
file = QString("(%1)").arg(file);
184+
180185
msg.replace("\n"," ");
181186

182187
//Restarts the parser
183-
if(xml_doc) restartParser();
188+
if(xml_doc)
189+
restartParser();
184190

185191
//Raise an exception with the error massege from the parser xml
186192
throw Exception(Exception::getErrorMessage(ErrorCode::LibXMLError)
187-
.arg(xml_error->line).arg(xml_error->int2).arg(msg).arg(file),
188-
ErrorCode::LibXMLError,__PRETTY_FUNCTION__,__FILE__,__LINE__,nullptr, xml_doc_filename);
193+
.arg(xml_error->line).arg(xml_error->int2).arg(msg, file),
194+
ErrorCode::LibXMLError, __PRETTY_FUNCTION__, __FILE__, __LINE__, nullptr,
195+
extra_info);
189196
}
190197

191198
//Gets the referênce to the root element on the document
@@ -247,12 +254,13 @@ void XmlParser::restartParser()
247254
xmlFreeDoc(xml_doc);
248255
xml_doc=nullptr;
249256
}
250-
dtd_decl=xml_buffer=xml_decl="";
257+
258+
dtd_decl = xml_buffer = xml_decl= "";
259+
xml_doc_filename = "";
251260

252261
while(!elems_stack.empty())
253262
elems_stack.pop();
254263

255-
xml_doc_filename="";
256264
xmlResetLastError();
257265
}
258266

libs/libparsers/src/xmlparser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ class __libparsers XmlParser {
6666

6767
//! \brief Stores the document DTD declaration
6868
QString dtd_decl,
69+
6970
//! \brief Stores XML document to be analyzed
7071
xml_buffer,
72+
7173
/*! \brief Stores the declaration <?xml?>. If this isn't exists it will be
72-
a default declaration. */
74+
* a default declaration. */
7375
xml_decl;
7476

7577
/*! \brief Remove the original DTD from the document. This is done to evit that

0 commit comments

Comments
 (0)