Skip to content

Commit

Permalink
Surround date in toString with quotes. Fix pocoproject#1062
Browse files Browse the repository at this point in the history
  • Loading branch information
fbraem committed Dec 8, 2015
1 parent cf02d38 commit 0f7729c
Showing 1 changed file with 14 additions and 49 deletions.
63 changes: 14 additions & 49 deletions MongoDB/include/Poco/MongoDB/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Poco/Nullable.h"
#include "Poco/NumberFormatter.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/UTF8String.h"
#include "Poco/MongoDB/MongoDB.h"
#include "Poco/MongoDB/BSONReader.h"
#include "Poco/MongoDB/BSONWriter.h"
Expand Down Expand Up @@ -79,7 +80,7 @@ inline std::string Element::name() const
typedef std::list<Element::Ptr> ElementSet;


template<typename T>
template<typename T>
struct ElementTraits
{
};
Expand Down Expand Up @@ -109,51 +110,11 @@ struct ElementTraits<std::string>

static std::string toString(const std::string& value, int indent = 0)
{
std::ostringstream oss;

oss << '"';

for(std::string::const_iterator it = value.begin(); it != value.end(); ++it)
{
switch (*it)
{
case '"':
oss << "\\\"";
break;
case '\\':
oss << "\\\\";
break;
case '\b':
oss << "\\b";
break;
case '\f':
oss << "\\f";
break;
case '\n':
oss << "\\n";
break;
case '\r':
oss << "\\r";
break;
case '\t':
oss << "\\t";
break;
default:
{
if ( *it > 0 && *it <= 0x1F )
{
oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*it);
}
else
{
oss << *it;
}
break;
}
}
}
oss << '"';
return oss.str();
std::string result;
result.append(1, '"');
result.append(UTF8::escape(value));
result.append(1, '"');
return result;
}
};

Expand Down Expand Up @@ -231,7 +192,11 @@ struct ElementTraits<Timestamp>

static std::string toString(const Timestamp& value, int indent = 0)
{
return DateTimeFormatter::format(value, "%Y-%m-%dT%H:%M:%s%z");
std::string result;
result.append(1, '"');
result.append(DateTimeFormatter::format(value, "%Y-%m-%dT%H:%M:%s%z"));
result.append(1, '"');
return result;
}
};

Expand Down Expand Up @@ -308,7 +273,7 @@ class ConcreteElement : public Element
{
}


T value() const
{
return _value;
Expand All @@ -320,7 +285,7 @@ class ConcreteElement : public Element
return ElementTraits<T>::toString(_value, indent);
}


int type() const
{
return ElementTraits<T>::TypeId;
Expand Down

0 comments on commit 0f7729c

Please sign in to comment.