From e8d465441900ed8af575172255b3c116a305d6b5 Mon Sep 17 00:00:00 2001 From: Alex Bocharov Date: Tue, 7 Aug 2018 18:04:39 +0100 Subject: [PATCH] Remove FormatSettings default value for writeJSONString and add tests for output_format_json_escape_forward_slashes. --- dbms/src/Common/FileChecker.cpp | 3 ++- dbms/src/Formats/JSONRowOutputStream.cpp | 4 ++-- dbms/src/IO/WriteHelpers.h | 6 +++--- ...0685_output_format_json_escape_forward_slashes.reference | 2 ++ .../00685_output_format_json_escape_forward_slashes.sql | 5 +++++ 5 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.reference create mode 100644 dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.sql diff --git a/dbms/src/Common/FileChecker.cpp b/dbms/src/Common/FileChecker.cpp index e3b1db745ca..bd8e00e38c0 100644 --- a/dbms/src/Common/FileChecker.cpp +++ b/dbms/src/Common/FileChecker.cpp @@ -95,13 +95,14 @@ void FileChecker::save() const /// So complex JSON structure - for compatibility with the old format. writeCString("{\"yandex\":{", out); + auto settings = FormatSettings(); for (auto it = map.begin(); it != map.end(); ++it) { if (it != map.begin()) writeString(",", out); /// `escapeForFileName` is not really needed. But it is left for compatibility with the old code. - writeJSONString(escapeForFileName(it->first), out); + writeJSONString(escapeForFileName(it->first), out, settings); writeString(":{\"size\":\"", out); writeIntText(it->second, out); writeString("\"}", out); diff --git a/dbms/src/Formats/JSONRowOutputStream.cpp b/dbms/src/Formats/JSONRowOutputStream.cpp index 799564ddb04..89f57669a3e 100644 --- a/dbms/src/Formats/JSONRowOutputStream.cpp +++ b/dbms/src/Formats/JSONRowOutputStream.cpp @@ -50,7 +50,7 @@ void JSONRowOutputStream::writePrefix() writeString(fields[i].name, *ostr); writeCString(",\n", *ostr); writeCString("\t\t\t\"type\": ", *ostr); - writeJSONString(fields[i].type->getName(), *ostr); + writeJSONString(fields[i].type->getName(), *ostr, settings); writeChar('\n', *ostr); writeCString("\t\t}", *ostr); @@ -149,7 +149,7 @@ void JSONRowOutputStream::writeTotals() writeCString(",\n", *ostr); writeCString("\t\t", *ostr); - writeJSONString(column.name, *ostr); + writeJSONString(column.name, *ostr, settings); writeCString(": ", *ostr); column.type->serializeTextJSON(*column.column.get(), 0, *ostr, settings); } diff --git a/dbms/src/IO/WriteHelpers.h b/dbms/src/IO/WriteHelpers.h index 96d028faa81..932b0744d0c 100644 --- a/dbms/src/IO/WriteHelpers.h +++ b/dbms/src/IO/WriteHelpers.h @@ -174,7 +174,7 @@ inline void writeString(const StringRef & ref, WriteBuffer & buf) * - it is assumed that string is in UTF-8, the invalid UTF-8 is not processed * - all other non-ASCII characters remain as is */ -inline void writeJSONString(const char * begin, const char * end, WriteBuffer & buf, const FormatSettings & settings = FormatSettings()) +inline void writeJSONString(const char * begin, const char * end, WriteBuffer & buf, const FormatSettings & settings) { writeChar('"', buf); for (const char * it = begin; it != end; ++it) @@ -313,13 +313,13 @@ void writeAnyEscapedString(const char * begin, const char * end, WriteBuffer & b } -inline void writeJSONString(const String & s, WriteBuffer & buf, const FormatSettings & settings = FormatSettings()) +inline void writeJSONString(const String & s, WriteBuffer & buf, const FormatSettings & settings) { writeJSONString(s.data(), s.data() + s.size(), buf, settings); } -inline void writeJSONString(const StringRef & ref, WriteBuffer & buf, const FormatSettings & settings = FormatSettings()) +inline void writeJSONString(const StringRef & ref, WriteBuffer & buf, const FormatSettings & settings) { writeJSONString(ref.data, ref.data + ref.size, buf, settings); } diff --git a/dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.reference b/dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.reference new file mode 100644 index 00000000000..d415e95f350 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.reference @@ -0,0 +1,2 @@ +{"url":"\/some\/cool\/url"} +{"url":"/some/cool/url"} diff --git a/dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.sql b/dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.sql new file mode 100644 index 00000000000..9842b07a8b0 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00685_output_format_json_escape_forward_slashes.sql @@ -0,0 +1,5 @@ +SET output_format_json_escape_forward_slashes = 1; +select '/some/cool/url' as url format JSONEachRow; +SET output_format_json_escape_forward_slashes = 0; +select '/some/cool/url' as url format JSONEachRow; +SET output_format_json_escape_forward_slashes = 1;