Skip to content

Commit f04923b

Browse files
allanrenuccicopybara-github
authored andcommitted
Fix handling of strings with null character.
PiperOrigin-RevId: 752197087
1 parent f72517e commit f04923b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

tsl/platform/tstring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class tstring {
212212
// Support for absl::StrCat() etc.
213213
template <typename Sink>
214214
friend void AbslStringify(Sink& sink, const tstring& str) {
215-
absl::Format(&sink, "%s", str.data());
215+
absl::Format(&sink, "%s", absl::string_view(str));
216216
}
217217
};
218218

tsl/platform/tstring_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ TEST(TF_TStringTest, Conversion) {
266266

267267
EXPECT_STREQ(kLongString, s53.data());
268268
EXPECT_EQ(kLongStringLen, s53.size());
269+
270+
EXPECT_EQ(std::string("\0a", 2), absl::StrCat(tstring("\0a", 2)));
269271
}
270272

271273
TEST(TF_TStringTest, Allocation) {

0 commit comments

Comments
 (0)