Browse Source

HPCC-11961 Roxie json output of scalar data should be quoted

Signed-off-by: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Anthony Fishbeck 11 years ago
parent
commit
c0574beb6e
3 changed files with 25 additions and 11 deletions
  1. 22 0
      common/thorhelper/roxiehelper.cpp
  2. 2 0
      common/thorhelper/roxiehelper.hpp
  3. 1 11
      roxie/ccd/ccdcontext.cpp

+ 22 - 0
common/thorhelper/roxiehelper.cpp

@@ -885,6 +885,22 @@ void FlushingStringBuffer::encodeString(const char *x, unsigned len, bool utf8)
         append(len, x);
 }
 
+void FlushingStringBuffer::encodeData(const void *data, unsigned len)
+{
+    static char hexchar[] = "0123456789ABCDEF";
+    if (mlFmt==MarkupFmt_XML)
+    {
+        const byte *field = (const byte *) data;
+        for (int i = 0; i < len; i++)
+        {
+            append(hexchar[field[i] >> 4]);
+            append(hexchar[field[i] & 0x0f]);
+        }
+    }
+    else
+        append(len, (const char *) data);
+}
+
 void FlushingStringBuffer::addPayload(StringBuffer &s, unsigned int reserve)
 {
     if (!s.length())
@@ -1107,6 +1123,12 @@ void FlushingJsonBuffer::encodeString(const char *x, unsigned len, bool utf8)
     appendJSONStringValue(s, NULL, len, x, true);
 }
 
+void FlushingJsonBuffer::encodeData(const void *data, unsigned len)
+{
+    CriticalBlock b(crit);
+    appendJSONDataValue(s, NULL, len, data);
+}
+
 void FlushingJsonBuffer::startDataset(const char *elementName, const char *resultName, unsigned sequence, bool _extend, const IProperties *xmlns)
 {
     CriticalBlock b(crit);

+ 2 - 0
common/thorhelper/roxiehelper.hpp

@@ -156,6 +156,7 @@ public:
     virtual void append(unsigned len, const char *data);
     virtual void appendf(const char *format, ...) __attribute__((format(printf, 2, 3)));
     virtual void encodeString(const char *x, unsigned len, bool utf8=false);
+    virtual void encodeData(const void *data, unsigned len);
     virtual void flushXML(StringBuffer &current, bool isClosing);
     virtual void flush(bool closing) ;
     virtual void addPayload(StringBuffer &s, unsigned int reserve=0);
@@ -174,6 +175,7 @@ public:
     }
 
     void encodeString(const char *x, unsigned len, bool utf8=false);
+    void encodeData(const void *data, unsigned len);
     void startDataset(const char *elementName, const char *resultName, unsigned sequence, bool _extend = false, const IProperties *xmlns=NULL);
     void startScalar(const char *resultName, unsigned sequence);
 };

+ 1 - 11
roxie/ccd/ccdcontext.cpp

@@ -3029,17 +3029,7 @@ public:
             if (r)
             {
                 r->startScalar(name, sequence);
-                if (isRaw)
-                    r->append(len, (const char *) data);
-                else
-                {
-                    const byte *field = (const byte *) data;
-                    for (int i = 0; i < len; i++)
-                    {
-                        r->append(hexchar[field[i] >> 4]);
-                        r->append(hexchar[field[i] & 0x0f]);
-                    }
-                }
+                r->encodeData(data, len);
             }
         }
         if (workUnit)