Skip to content

Commit

Permalink
Harden operator wstring_view (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Mar 3, 2020
1 parent 7b70db8 commit 4b77215
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion strings/base_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ WINRT_EXPORT namespace winrt
}
else
{
return {};
return { L"", 0 };
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/test/hstring_empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ TEST_CASE("hstring_empty")
// Using wcslen to both validate that the strings are empty *and* that they are not null.
REQUIRE(wcslen(s.c_str()) == 0);
REQUIRE(wcslen(s.data()) == 0);

std::wstring_view v = s;
REQUIRE(v.empty());
REQUIRE(v.size() == 0);
REQUIRE(v == L""sv);
REQUIRE(std::distance(v.begin(), v.end()) == 0);

// Using wcslen to both validate that the strings are empty *and* that they are not null.
// This is not guaranteed for wstring_view, but is assumed by some code that creates a
// wstring_view from an hstring.
REQUIRE(wcslen(v.data()) == 0);
}

0 comments on commit 4b77215

Please sign in to comment.