Remove FormatSettings default value for writeJSONString and add tests for output_format_json_escape_forward_slashes.

This commit is contained in:
Alex Bocharov 2018-08-07 18:04:39 +01:00 committed by alexey-milovidov
parent 4e7b2927dd
commit e8d4654419
5 changed files with 14 additions and 6 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -0,0 +1,2 @@
{"url":"\/some\/cool\/url"}
{"url":"/some/cool/url"}

View File

@ -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;