Skip to content

Commit f43fceb

Browse files
committed
fix: escape for getting string literal
1 parent a89924d commit f43fceb

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/iceberg/expression/literal.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <cstdint>
2525
#include <string>
2626

27+
#include <nlohmann/json.hpp>
28+
2729
#include "iceberg/util/checked_cast.h"
2830
#include "iceberg/util/conversions.h"
2931
#include "iceberg/util/macros.h"
@@ -488,7 +490,8 @@ std::string Literal::ToString() const {
488490
.value_or("invalid literal of type decimal");
489491
}
490492
case TypeId::kString: {
491-
return "\"" + std::get<std::string>(value_) + "\"";
493+
nlohmann::json json = std::get<std::string>(value_);
494+
return json.dump();
492495
}
493496
case TypeId::kUuid: {
494497
return std::get<Uuid>(value_).ToString();

src/iceberg/test/literal_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ INSTANTIATE_TEST_SUITE_P(
546546
.expected_type_id = TypeId::kDecimal,
547547
.expected_string = "0"},
548548
BasicLiteralTestParam{.test_name = "String",
549-
.literal = Literal::String("hello world"),
549+
.literal = Literal::String("hello \" world"),
550550
.expected_type_id = TypeId::kString,
551-
.expected_string = "\"hello world\""},
551+
.expected_string = "\"hello \\\" world\""},
552552
BasicLiteralTestParam{
553553
.test_name = "Uuid",
554554
.literal = Literal::UUID(

0 commit comments

Comments
 (0)