rgw/rgw_formats.cc \
rgw/rgw_log.cc \
rgw/rgw_multi.cc \
- rgw/rgw_escape.c \
rgw/rgw_env.cc
my_radosgw_ldadd = \
unittest_mime_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
check_PROGRAMS += unittest_mime
-unittest_rgw_escape_SOURCES = test/rgw_escape.cc rgw/rgw_escape.c
-unittest_rgw_escape_LDFLAGS = -pthread ${AM_LDFLAGS}
-unittest_rgw_escape_LDADD = ${UNITTEST_LDADD} $(LIBGLOBAL_LDA)
-unittest_rgw_escape_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
-check_PROGRAMS += unittest_rgw_escape
+unittest_escape_SOURCES = test/escape.cc
+unittest_escape_LDFLAGS = -pthread ${AM_LDFLAGS}
+unittest_escape_LDADD = ${UNITTEST_LDADD} $(LIBGLOBAL_LDA)
+unittest_escape_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
+check_PROGRAMS += unittest_escape
unittest_strtol_SOURCES = test/strtol.cc
unittest_strtol_LDFLAGS = -pthread ${AM_LDFLAGS}
common/perf_counters.cc \
common/admin_socket.cc \
common/admin_socket_client.cc \
+ common/escape.c \
common/Clock.cc \
common/Timer.cc \
common/Finisher.cc \
common/compiler_extensions.h\
common/debug.h\
common/dout.h\
+ common/escape.h\
common/version.h\
common/hex.h\
common/entity_name.h\
rgw/rgw_rest_os.h\
rgw/rgw_rest_s3.h\
rgw/rgw_user.h\
- rgw/rgw_escape.h\
sample.ceph.conf\
tools/common.h\
tools/gui.h\
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
#define LARGE_SIZE 8192
-#include <stdarg.h>
-#include <stdio.h>
-#include <inttypes.h>
-
-#include <iostream>
-
#include "assert.h"
#include "Formatter.h"
+#include "common/escape.h"
+
+#include <inttypes.h>
+#include <iostream>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
// -----------------------
namespace ceph {
void JSONFormatter::print_quoted_string(const char *s)
{
- m_ss << '\"';
- while (*s) {
- if (*s == '\\')
- m_ss << "\\";
- else if (*s == '\"')
- m_ss << "\\\"";
- else if (*s < 32) {
- // do a few common control characters
- switch (*s) {
- case '\n':
- m_ss << "\\n";
- break;
- case '\r':
- m_ss << "\\r";
- break;
- case '\t':
- m_ss << "\\t";
- break;
- default:
- {
- // otherwise...
- char s[10];
- sprintf(s, "\\u%04x", (int)*s);
- }
- }
- } else
- m_ss << *s;
- s++;
- }
- m_ss << '\"';
+ int len = escape_json_attr_len(s);
+ char *escaped = (char*)malloc(len);
+ escape_json_attr(s, escaped);
+ m_ss << '\"' << escaped << '\"';
+ free(escaped);
}
void JSONFormatter::print_name(const char *name)
#ifndef CEPH_FORMATTER_H
#define CEPH_FORMATTER_H
+#include <inttypes.h>
+#include <iostream>
+#include <list>
#include <ostream>
#include <sstream>
+#include <stdarg.h>
#include <string>
-#include <list>
namespace ceph {
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include "common/escape.h"
+
+#include <stdio.h>
+#include <string.h>
+
+/*
+ * Some functions for escaping RGW responses
+ */
+
+/* Static string length */
+#define SSTRL(x) ((sizeof(x)/sizeof(x[0])) - 1)
+
+#define LESS_THAN_XESCAPE "<"
+#define AMPERSAND_XESCAPE "&"
+#define GREATER_THAN_XESCAPE ">"
+#define SGL_QUOTE_XESCAPE "'"
+#define DBL_QUOTE_XESCAPE """
+
+int escape_xml_attr_len(const char *buf)
+{
+ const char *b;
+ int ret = 0;
+ for (b = buf; *b; ++b) {
+ unsigned char c = *b;
+ switch (c) {
+ case '<':
+ ret += SSTRL(LESS_THAN_XESCAPE);
+ break;
+ case '&':
+ ret += SSTRL(AMPERSAND_XESCAPE);
+ break;
+ case '>':
+ ret += SSTRL(GREATER_THAN_XESCAPE);
+ break;
+ case '\'':
+ ret += SSTRL(SGL_QUOTE_XESCAPE);
+ break;
+ case '"':
+ ret += SSTRL(DBL_QUOTE_XESCAPE);
+ break;
+ default:
+ // Escape control characters.
+ if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
+ (c == 0x7f)) {
+ ret += 6;
+ }
+ else {
+ ret++;
+ }
+ }
+ }
+ // leave room for null terminator
+ ret++;
+ return ret;
+}
+
+void escape_xml_attr(const char *buf, char *out)
+{
+ char *o = out;
+ const char *b;
+ for (b = buf; *b; ++b) {
+ unsigned char c = *b;
+ switch (c) {
+ case '<':
+ memcpy(o, LESS_THAN_XESCAPE, SSTRL(LESS_THAN_XESCAPE));
+ o += SSTRL(LESS_THAN_XESCAPE);
+ break;
+ case '&':
+ memcpy(o, AMPERSAND_XESCAPE, SSTRL(AMPERSAND_XESCAPE));
+ o += SSTRL(AMPERSAND_XESCAPE);
+ break;
+ case '>':
+ memcpy(o, GREATER_THAN_XESCAPE, SSTRL(GREATER_THAN_XESCAPE));
+ o += SSTRL(GREATER_THAN_XESCAPE);
+ break;
+ case '\'':
+ memcpy(o, SGL_QUOTE_XESCAPE, SSTRL(SGL_QUOTE_XESCAPE));
+ o += SSTRL(SGL_QUOTE_XESCAPE);
+ break;
+ case '"':
+ memcpy(o, DBL_QUOTE_XESCAPE, SSTRL(DBL_QUOTE_XESCAPE));
+ o += SSTRL(DBL_QUOTE_XESCAPE);
+ break;
+ default:
+ // Escape control characters.
+ if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
+ (c == 0x7f)) {
+ sprintf(o, "&#x%02x;", c);
+ o += 6;
+ }
+ else {
+ *o++ = c;
+ }
+ break;
+ }
+ }
+ // null terminator
+ *o = '\0';
+}
+
+#define SGL_QUOTE_JESCAPE "\\'"
+#define DBL_QUOTE_JESCAPE "\\\""
+#define BACKSLASH_JESCAPE "\\\\"
+#define SLASH_JESCAPE "\\/"
+#define TAB_JESCAPE "\\t"
+#define NEWLINE_JESCAPE "\\n"
+
+int escape_json_attr_len(const char *buf)
+{
+ const char *b;
+ int ret = 0;
+ for (b = buf; *b; ++b) {
+ unsigned char c = *b;
+ switch (c) {
+ case '\'':
+ ret += SSTRL(SGL_QUOTE_JESCAPE);
+ break;
+ case '"':
+ ret += SSTRL(DBL_QUOTE_JESCAPE);
+ break;
+ case '\\':
+ ret += SSTRL(BACKSLASH_JESCAPE);
+ break;
+ case '/':
+ ret += SSTRL(SLASH_JESCAPE);
+ break;
+ case '\t':
+ ret += SSTRL(TAB_JESCAPE);
+ break;
+ case '\n':
+ ret += SSTRL(NEWLINE_JESCAPE);
+ break;
+ default:
+ // Escape control characters.
+ if ((c < 0x20) || (c == 0x7f)) {
+ ret += 5;
+ }
+ else {
+ ret++;
+ }
+ }
+ }
+ // leave room for null terminator
+ ret++;
+ return ret;
+}
+
+void escape_json_attr(const char *buf, char *out)
+{
+ char *o = out;
+ const char *b;
+ for (b = buf; *b; ++b) {
+ unsigned char c = *b;
+ switch (c) {
+ case '\'':
+ memcpy(o, SGL_QUOTE_JESCAPE, SSTRL(SGL_QUOTE_JESCAPE));
+ o += SSTRL(SGL_QUOTE_JESCAPE);
+ break;
+ case '"':
+ memcpy(o, DBL_QUOTE_JESCAPE, SSTRL(DBL_QUOTE_JESCAPE));
+ o += SSTRL(DBL_QUOTE_JESCAPE);
+ break;
+ case '\\':
+ memcpy(o, BACKSLASH_JESCAPE, SSTRL(BACKSLASH_JESCAPE));
+ o += SSTRL(BACKSLASH_JESCAPE);
+ break;
+ case '/':
+ memcpy(o, SLASH_JESCAPE, SSTRL(SLASH_JESCAPE));
+ o += SSTRL(SLASH_JESCAPE);
+ break;
+ case '\t':
+ memcpy(o, TAB_JESCAPE, SSTRL(TAB_JESCAPE));
+ o += SSTRL(TAB_JESCAPE);
+ break;
+ case '\n':
+ memcpy(o, NEWLINE_JESCAPE, SSTRL(NEWLINE_JESCAPE));
+ o += SSTRL(NEWLINE_JESCAPE);
+ break;
+ default:
+ // Escape control characters.
+ if ((c < 0x20) || (c == 0x7f)) {
+ sprintf(o, "\\%04x", c);
+ o += 5;
+ }
+ else {
+ *o++ = c;
+ }
+ break;
+ }
+ }
+ // null terminator
+ *o = '\0';
+}
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#ifndef CEPH_RGW_ESCAPE_H
+#define CEPH_RGW_ESCAPE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Returns the length of a buffer that would be needed to escape 'buf'
+ * as an XML attrribute
+ */
+int escape_xml_attr_len(const char *buf);
+
+/* Escapes 'buf' as an XML attribute. Assumes that 'out' is at least long
+ * enough to fit the output. You can find out the required length by calling
+ * escape_xml_attr_len first.
+ */
+void escape_xml_attr(const char *buf, char *out);
+
+/* Returns the length of a buffer that would be needed to escape 'buf'
+ * as an JSON attrribute
+ */
+int escape_json_attr_len(const char *buf);
+
+/* Escapes 'buf' as an JSON attribute. Assumes that 'out' is at least long
+ * enough to fit the output. You can find out the required length by calling
+ * escape_json_attr_len first.
+ */
+void escape_json_attr(const char *buf, char *out);
+
+/* Note: we escape control characters. Although the XML spec doesn't actually
+ * require this, Amazon does it in their XML responses.
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
*
*/
-
-
#include "FileStore.h"
#include "common/BackTrace.h"
#include "include/types.h"
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2011 New Dream Network
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation. See file COPYING.
- *
- */
-
-#include "rgw/rgw_escape.h"
-
-#include <stdio.h>
-#include <string.h>
-
-/*
- * Some functions for escaping RGW responses
- */
-
-/* Static string length */
-#define SSTRL(x) ((sizeof(x)/sizeof(x[0])) - 1)
-
-#define LESS_THAN_XESCAPE "<"
-#define AMPERSAND_XESCAPE "&"
-#define GREATER_THAN_XESCAPE ">"
-#define SGL_QUOTE_XESCAPE "'"
-#define DBL_QUOTE_XESCAPE """
-
-int escape_xml_attr_len(const char *buf)
-{
- const char *b;
- int ret = 0;
- for (b = buf; *b; ++b) {
- unsigned char c = *b;
- switch (c) {
- case '<':
- ret += SSTRL(LESS_THAN_XESCAPE);
- break;
- case '&':
- ret += SSTRL(AMPERSAND_XESCAPE);
- break;
- case '>':
- ret += SSTRL(GREATER_THAN_XESCAPE);
- break;
- case '\'':
- ret += SSTRL(SGL_QUOTE_XESCAPE);
- break;
- case '"':
- ret += SSTRL(DBL_QUOTE_XESCAPE);
- break;
- default:
- // Escape control characters.
- if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
- (c == 0x7f)) {
- ret += 6;
- }
- else {
- ret++;
- }
- }
- }
- // leave room for null terminator
- ret++;
- return ret;
-}
-
-void escape_xml_attr(const char *buf, char *out)
-{
- char *o = out;
- const char *b;
- for (b = buf; *b; ++b) {
- unsigned char c = *b;
- switch (c) {
- case '<':
- memcpy(o, LESS_THAN_XESCAPE, SSTRL(LESS_THAN_XESCAPE));
- o += SSTRL(LESS_THAN_XESCAPE);
- break;
- case '&':
- memcpy(o, AMPERSAND_XESCAPE, SSTRL(AMPERSAND_XESCAPE));
- o += SSTRL(AMPERSAND_XESCAPE);
- break;
- case '>':
- memcpy(o, GREATER_THAN_XESCAPE, SSTRL(GREATER_THAN_XESCAPE));
- o += SSTRL(GREATER_THAN_XESCAPE);
- break;
- case '\'':
- memcpy(o, SGL_QUOTE_XESCAPE, SSTRL(SGL_QUOTE_XESCAPE));
- o += SSTRL(SGL_QUOTE_XESCAPE);
- break;
- case '"':
- memcpy(o, DBL_QUOTE_XESCAPE, SSTRL(DBL_QUOTE_XESCAPE));
- o += SSTRL(DBL_QUOTE_XESCAPE);
- break;
- default:
- // Escape control characters.
- if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
- (c == 0x7f)) {
- sprintf(o, "&#x%02x;", c);
- o += 6;
- }
- else {
- *o++ = c;
- }
- break;
- }
- }
- // null terminator
- *o = '\0';
-}
-
-#define SGL_QUOTE_JESCAPE "\\'"
-#define DBL_QUOTE_JESCAPE "\\\""
-#define BACKSLASH_JESCAPE "\\\\"
-#define SLASH_JESCAPE "\\/"
-#define TAB_JESCAPE "\\t"
-#define NEWLINE_JESCAPE "\\n"
-
-int escape_json_attr_len(const char *buf)
-{
- const char *b;
- int ret = 0;
- for (b = buf; *b; ++b) {
- unsigned char c = *b;
- switch (c) {
- case '\'':
- ret += SSTRL(SGL_QUOTE_JESCAPE);
- break;
- case '"':
- ret += SSTRL(DBL_QUOTE_JESCAPE);
- break;
- case '\\':
- ret += SSTRL(BACKSLASH_JESCAPE);
- break;
- case '/':
- ret += SSTRL(SLASH_JESCAPE);
- break;
- case '\t':
- ret += SSTRL(TAB_JESCAPE);
- break;
- case '\n':
- ret += SSTRL(NEWLINE_JESCAPE);
- break;
- default:
- // Escape control characters.
- if ((c < 0x20) || (c == 0x7f)) {
- ret += 5;
- }
- else {
- ret++;
- }
- }
- }
- // leave room for null terminator
- ret++;
- return ret;
-}
-
-void escape_json_attr(const char *buf, char *out)
-{
- char *o = out;
- const char *b;
- for (b = buf; *b; ++b) {
- unsigned char c = *b;
- switch (c) {
- case '\'':
- memcpy(o, SGL_QUOTE_JESCAPE, SSTRL(SGL_QUOTE_JESCAPE));
- o += SSTRL(SGL_QUOTE_JESCAPE);
- break;
- case '"':
- memcpy(o, DBL_QUOTE_JESCAPE, SSTRL(DBL_QUOTE_JESCAPE));
- o += SSTRL(DBL_QUOTE_JESCAPE);
- break;
- case '\\':
- memcpy(o, BACKSLASH_JESCAPE, SSTRL(BACKSLASH_JESCAPE));
- o += SSTRL(BACKSLASH_JESCAPE);
- break;
- case '/':
- memcpy(o, SLASH_JESCAPE, SSTRL(SLASH_JESCAPE));
- o += SSTRL(SLASH_JESCAPE);
- break;
- case '\t':
- memcpy(o, TAB_JESCAPE, SSTRL(TAB_JESCAPE));
- o += SSTRL(TAB_JESCAPE);
- break;
- case '\n':
- memcpy(o, NEWLINE_JESCAPE, SSTRL(NEWLINE_JESCAPE));
- o += SSTRL(NEWLINE_JESCAPE);
- break;
- default:
- // Escape control characters.
- if ((c < 0x20) || (c == 0x7f)) {
- sprintf(o, "\\%04x", c);
- o += 5;
- }
- else {
- *o++ = c;
- }
- break;
- }
- }
- // null terminator
- *o = '\0';
-}
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2011 New Dream Network
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation. See file COPYING.
- *
- */
-
-#ifndef CEPH_RGW_ESCAPE_H
-#define CEPH_RGW_ESCAPE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Returns the length of a buffer that would be needed to escape 'buf'
- * as an XML attrribute
- */
-int escape_xml_attr_len(const char *buf);
-
-/* Escapes 'buf' as an XML attribute. Assumes that 'out' is at least long
- * enough to fit the output. You can find out the required length by calling
- * escape_xml_attr_len first.
- */
-void escape_xml_attr(const char *buf, char *out);
-
-/* Returns the length of a buffer that would be needed to escape 'buf'
- * as an JSON attrribute
- */
-int escape_json_attr_len(const char *buf);
-
-/* Escapes 'buf' as an JSON attribute. Assumes that 'out' is at least long
- * enough to fit the output. You can find out the required length by calling
- * escape_json_attr_len first.
- */
-void escape_json_attr(const char *buf, char *out);
-
-/* Note: we escape control characters. Although the XML spec doesn't actually
- * require this, Amazon does it in their XML responses.
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-#include "rgw_escape.h"
-#include "rgw_common.h"
-#include "rgw_formats.h"
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include "common/escape.h"
+#include "rgw/rgw_common.h"
+#include "rgw/rgw_formats.h"
/* Plain */
void RGWFormatter_Plain::formatter_init()
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+#include "common/escape.h"
+#include "gtest/gtest.h"
+#include <stdint.h>
+
+static std::string escape_xml_attrs(const char *str)
+{
+ int len = escape_xml_attr_len(str);
+ char out[len];
+ escape_xml_attr(str, out);
+ return out;
+}
+
+TEST(EscapeXml, PassThrough) {
+ ASSERT_EQ(escape_xml_attrs("simplicity itself"), "simplicity itself");
+ ASSERT_EQ(escape_xml_attrs(""), "");
+ ASSERT_EQ(escape_xml_attrs("simple examples please!"), "simple examples please!");
+}
+
+TEST(EscapeXml, EntityRefs1) {
+ ASSERT_EQ(escape_xml_attrs("The \"scare quotes\""), "The "scare quotes"");
+ ASSERT_EQ(escape_xml_attrs("I <3 XML"), "I <3 XML");
+ ASSERT_EQ(escape_xml_attrs("Some 'single' \"quotes\" here"),
+ "Some 'single' "quotes" here");
+}
+
+TEST(EscapeXml, ControlChars) {
+ uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
+ ASSERT_EQ(escape_xml_attrs((char*)cc1), "");
+
+ uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
+ ASSERT_EQ(escape_xml_attrs((char*)cc2), "abc");
+}
+
+TEST(EscapeXml, Utf8) {
+ uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
+ ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
+
+ uint8_t cc2[] = { 0x3c, 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x3e, 0x0a, 0x0 };
+ uint8_t cc2_out[] = { 0x26, 0x6c, 0x74, 0x3b, 0xe6, 0xb1, 0x89, 0xe5,
+ 0xad, 0x97, 0x26, 0x67, 0x74, 0x3b, 0x0a, 0x0 };
+ ASSERT_EQ(escape_xml_attrs((const char*)cc2), (const char*)cc2_out);
+}
+
+static std::string escape_json_attrs(const char *str)
+{
+ int len = escape_json_attr_len(str);
+ char out[len];
+ escape_json_attr(str, out);
+ return out;
+}
+
+TEST(EscapeJson, PassThrough) {
+ ASSERT_EQ(escape_json_attrs("simplicity itself"), "simplicity itself");
+ ASSERT_EQ(escape_json_attrs(""), "");
+ ASSERT_EQ(escape_json_attrs("simple examples please!"), "simple examples please!");
+}
+
+TEST(EscapeJson, Escapes1) {
+ ASSERT_EQ(escape_json_attrs("The \"scare quotes\""),
+ "The \\\"scare quotes\\\"");
+ ASSERT_EQ(escape_json_attrs("I <3 JSON"), "I <3 JSON");
+ ASSERT_EQ(escape_json_attrs(
+ "JSON calls a slash / backslash a solidus / reverse solidus"),
+ "JSON calls a slash \\/ backslash a solidus \\/ reverse solidus");
+ ASSERT_EQ(escape_json_attrs("Some 'single' \"quotes\" here"),
+ "Some \\'single\\' \\\"quotes\\\" here");
+ ASSERT_EQ(escape_json_attrs("tabs\tand\tnewlines\n, oh my"),
+ "tabs\\tand\\tnewlines\\n, oh my");
+}
+
+TEST(EscapeJson, ControlChars) {
+ uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
+ ASSERT_EQ(escape_json_attrs((char*)cc1), "\\0001\\0002\\0003");
+
+ uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
+ ASSERT_EQ(escape_json_attrs((char*)cc2), "abc\\007f");
+}
+
+TEST(EscapeJson, Utf8) {
+ uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
+ ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
+}
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2011 New Dream Network
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation. See file COPYING.
- *
- */
-#include "rgw/rgw_escape.h"
-#include "gtest/gtest.h"
-#include <stdint.h>
-
-static std::string escape_xml_attrs(const char *str)
-{
- int len = escape_xml_attr_len(str);
- char out[len];
- escape_xml_attr(str, out);
- return out;
-}
-
-TEST(EscapeXml, PassThrough) {
- ASSERT_EQ(escape_xml_attrs("simplicity itself"), "simplicity itself");
- ASSERT_EQ(escape_xml_attrs(""), "");
- ASSERT_EQ(escape_xml_attrs("simple examples please!"), "simple examples please!");
-}
-
-TEST(EscapeXml, EntityRefs1) {
- ASSERT_EQ(escape_xml_attrs("The \"scare quotes\""), "The "scare quotes"");
- ASSERT_EQ(escape_xml_attrs("I <3 XML"), "I <3 XML");
- ASSERT_EQ(escape_xml_attrs("Some 'single' \"quotes\" here"),
- "Some 'single' "quotes" here");
-}
-
-TEST(EscapeXml, ControlChars) {
- uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
- ASSERT_EQ(escape_xml_attrs((char*)cc1), "");
-
- uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
- ASSERT_EQ(escape_xml_attrs((char*)cc2), "abc");
-}
-
-TEST(EscapeXml, Utf8) {
- uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
- ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
-
- uint8_t cc2[] = { 0x3c, 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x3e, 0x0a, 0x0 };
- uint8_t cc2_out[] = { 0x26, 0x6c, 0x74, 0x3b, 0xe6, 0xb1, 0x89, 0xe5,
- 0xad, 0x97, 0x26, 0x67, 0x74, 0x3b, 0x0a, 0x0 };
- ASSERT_EQ(escape_xml_attrs((const char*)cc2), (const char*)cc2_out);
-}
-
-static std::string escape_json_attrs(const char *str)
-{
- int len = escape_json_attr_len(str);
- char out[len];
- escape_json_attr(str, out);
- return out;
-}
-
-TEST(EscapeJson, PassThrough) {
- ASSERT_EQ(escape_json_attrs("simplicity itself"), "simplicity itself");
- ASSERT_EQ(escape_json_attrs(""), "");
- ASSERT_EQ(escape_json_attrs("simple examples please!"), "simple examples please!");
-}
-
-TEST(EscapeJson, Escapes1) {
- ASSERT_EQ(escape_json_attrs("The \"scare quotes\""),
- "The \\\"scare quotes\\\"");
- ASSERT_EQ(escape_json_attrs("I <3 JSON"), "I <3 JSON");
- ASSERT_EQ(escape_json_attrs(
- "JSON calls a slash / backslash a solidus / reverse solidus"),
- "JSON calls a slash \\/ backslash a solidus \\/ reverse solidus");
- ASSERT_EQ(escape_json_attrs("Some 'single' \"quotes\" here"),
- "Some \\'single\\' \\\"quotes\\\" here");
- ASSERT_EQ(escape_json_attrs("tabs\tand\tnewlines\n, oh my"),
- "tabs\\tand\\tnewlines\\n, oh my");
-}
-
-TEST(EscapeJson, ControlChars) {
- uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
- ASSERT_EQ(escape_json_attrs((char*)cc1), "\\0001\\0002\\0003");
-
- uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
- ASSERT_EQ(escape_json_attrs((char*)cc2), "abc\\007f");
-}
-
-TEST(EscapeJson, Utf8) {
- uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
- ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
-}