Skip to content

Commit

Permalink
HPCC-26439 Allow string terminator in WU result when converting to CSV
Browse files Browse the repository at this point in the history
Inside a WU result string, covert \0 to "\000".

Signed-off-by: wangkx <[email protected]>
  • Loading branch information
wangkx committed Sep 1, 2021
1 parent a9d41dc commit 4ff2c07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions rtl/eclrtl/rtlformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,17 +1402,25 @@ unsigned CommonCSVWriter::getChildrenMaxColumnID(CCSVItem* item, unsigned& maxCo
return maxColumnID;
}

void CommonCSVWriter::escapeQuoted(unsigned len, char const* in, StringBuffer& out)
void CommonCSVWriter::escapeString(unsigned len, char const* in, StringBuffer& out)
{
char const* finger = in;
while (len--)
{
//RFC-4180, paragraph "If double-quotes are used to enclose fields, then a double-quote
//appearing inside a field must be escaped by preceding it with another double quote."
//unsigned newLen = 0;
if (*finger == '"')
out.append('"');
out.append(*finger);
if (*finger != '\0')
{
//RFC-4180, paragraph "If double-quotes are used to enclose fields, then a double-quote
//appearing inside a field must be escaped by preceding it with another double quote."
if (*finger == '"')
out.append('"');
out.append(*finger);
}
else
{
//null bytes should not occur, but encode them if they do to prevent problems elsewhere
out.append("\000");
}

finger++;
}
}
Expand Down Expand Up @@ -1544,7 +1552,7 @@ void CommonCSVWriter::addStringField(unsigned len, const char* field, const char
{
StringBuffer v;
v.append(csvQuote);
escapeQuoted(len, field, v);
escapeString(len, field, v);
v.append(csvQuote);
addContentField(v.str(), fieldName);
}
Expand Down
2 changes: 1 addition & 1 deletion rtl/eclrtl/rtlformat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class ECLRTL_API CommonCSVWriter: public CInterface, implements IXmlWriterExt
CIArrayOf<CCSVRow> contentRowsBuffer;
CIArrayOf<CXPathItem> dataXPath;//xpath in caller

void escapeQuoted(unsigned len, char const* in, StringBuffer& out);
void escapeString(unsigned len, char const* in, StringBuffer& out);
bool checkHeaderName(const char* name);
CCSVItem* getParentCSVItem();
CCSVItem* getCSVItemByFieldName(const char* name);
Expand Down

0 comments on commit 4ff2c07

Please sign in to comment.