Skip to content

Commit

Permalink
Fix #8542 - Escape HTML characters.
Browse files Browse the repository at this point in the history
Added an optional boolean argument to ConvertToEscape to not convert " and ' like it would in the original routine which was meant for XML. This is to support HTML4 mostly, but might as well be correct.
  • Loading branch information
jmarrec committed Feb 17, 2021
1 parent 0dcf25b commit 166feaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/EnergyPlus/OutputReportTabular.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14188,7 +14188,7 @@ namespace EnergyPlus::OutputReportTabular {
for (iCol = 1; iCol <= colsColumnLabels; ++iCol) {
outputLine = " <td align=\"right\">";
for (jRow = 1; jRow <= maxNumColLabelRows; ++jRow) {
outputLine += colLabelMulti(iCol, jRow);
outputLine += ConvertToEscaped(colLabelMulti(iCol, jRow), false);
if (jRow < maxNumColLabelRows) {
outputLine += "<br>";
}
Expand All @@ -14200,13 +14200,13 @@ namespace EnergyPlus::OutputReportTabular {
for (jRow = 1; jRow <= rowsBody; ++jRow) {
tbl_stream << " <tr>\n";
if (rowLabels(jRow) != "") {
tbl_stream << " <td align=\"right\">" << InsertCurrencySymbol(state, rowLabels(jRow), true) << "</td>\n";
tbl_stream << " <td align=\"right\">" << ConvertToEscaped(InsertCurrencySymbol(state, rowLabels(jRow), true), false) << "</td>\n";
} else {
tbl_stream << " <td align=\"right\">&nbsp;</td>\n";
}
for (iCol = 1; iCol <= colsBody; ++iCol) {
if (body(iCol, jRow) != "") {
tbl_stream << " <td align=\"right\">" << InsertCurrencySymbol(state, body(iCol, jRow), true) << "</td>\n";
tbl_stream << " <td align=\"right\">" << ConvertToEscaped(InsertCurrencySymbol(state, body(iCol, jRow), true), false) << "</td>\n";
} else {
tbl_stream << " <td align=\"right\">&nbsp;</td>\n";
}
Expand Down Expand Up @@ -14541,7 +14541,7 @@ namespace EnergyPlus::OutputReportTabular {
return s;
}

std::string ConvertToEscaped(std::string const &inString) // Input String
std::string ConvertToEscaped(std::string const &inString, bool isXML) // Input String
{
// SUBROUTINE INFORMATION:
// AUTHOR Jason Glazer
Expand All @@ -14552,7 +14552,10 @@ namespace EnergyPlus::OutputReportTabular {
// PURPOSE OF THIS SUBROUTINE:
// Convert to XML safe escaped character string
// so it excludes:
// " ' < > &
// " ' < > & degree-sign
// If isXML=false, it does an HTML conversion, so only ` < > & ` and degree sign
// Technically HTML4 doesn't support &quot, though most browsers would anyways.
// Also, escaping single and double quotes is only needed inside attributes

if (inString.empty()) return "";

Expand All @@ -14565,11 +14568,11 @@ namespace EnergyPlus::OutputReportTabular {
while (true) {
if (index == inputSize) break;
c = inString[index++];
if (c == '\"') {
if ((c == '\"') && isXML) {
s += "&quot;";
} else if (c == '&') {
s += "&amp;";
} else if (c == '\'') {
} else if ((c == '\'') && isXML) {
s += "&apos;";
} else if (c == '<') {
s += "&lt;";
Expand All @@ -14594,9 +14597,9 @@ namespace EnergyPlus::OutputReportTabular {
} else if (c == '\\') {
if (index == inputSize) break;
c = inString[index++];
if (c == '"') {
if ((c == '"') && isXML) {
s += "&quot;";
} else if (c == '\'') {
} else if ((c == '\'') && isXML) {
s += "&apos;";
} else if (c == 'u' || c == 'x') {
int remainingLen = inputSize - index;
Expand Down
3 changes: 2 additions & 1 deletion src/EnergyPlus/OutputReportTabular.hh
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ namespace OutputReportTabular {

std::string ConvertUnicodeToUTF8(unsigned long const codepoint);

std::string ConvertToEscaped(std::string const &inString); // Input String
std::string ConvertToEscaped(std::string const &inString, // Input String
bool isXML=true); // isXML if false assumes HTML and will not convert quotes and apostrophes, for HTML4

void DetermineBuildingFloorArea(EnergyPlusData &state);

Expand Down

4 comments on commit 166feaf

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8542_EscapeHTML (jmarrec) - Win64-Windows-10-VisualStudio-16: Tests Failed (0 of 0 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8542_EscapeHTML (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (3057 of 3057 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8542_EscapeHTML (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1581 of 1581 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8542_EscapeHTML (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (721 of 722 tests passed, 0 test warnings)

Failures:\n

integration Test Summary

  • Passed: 721
  • Timeout: 1

Build Badge Test Badge Coverage Badge

Please sign in to comment.