Explicitly disallows modifiers for use with %v.

PiperOrigin-RevId: 475636693
Change-Id: Idb7c2b9c36ad8e59f24ff7df179a207d301d9e89
pull/1283/head
Abseil Team 3 years ago committed by Copybara-Service
parent d859fafe1a
commit 55996e2e30
  1. 4
      absl/strings/internal/str_format/parser.cc
  2. 11
      absl/strings/str_format_test.cc

@ -202,6 +202,10 @@ const char *ConsumeConversion(const char *pos, const char *const end,
auto tag = GetTagForChar(c);
if (*(pos - 1) == 'v' && *(pos - 2) != '%') {
return nullptr;
}
if (ABSL_PREDICT_FALSE(!tag.is_conv())) {
if (ABSL_PREDICT_FALSE(!tag.is_length())) return nullptr;

@ -1020,6 +1020,17 @@ TEST_F(ParsedFormatTest, RegressionMixPositional) {
absl::FormatConversionCharSet::o>::New("%1$d %o")));
}
TEST_F(ParsedFormatTest, DisallowModifiersWithV) {
auto f = ParsedFormat<'v'>::New("ABC%80vDEF");
EXPECT_EQ(f, nullptr);
f = ParsedFormat<'v'>::New("ABC%0vDEF");
EXPECT_EQ(f, nullptr);
f = ParsedFormat<'v'>::New("ABC%.1vDEF");
EXPECT_EQ(f, nullptr);
}
using FormatWrapperTest = ::testing::Test;
// Plain wrapper for StrFormat.

Loading…
Cancel
Save