summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-09-06 12:58:40 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-09-06 12:59:19 -0700
commitd3c00b06b334311e23ab18f5d2b90938a07ce35d (patch)
treee1dd1d69d38d2ed02a145898790f9a6cdb03c58e /absl
parent60499cf45cde8e3354b58317efac7488cc5151b2 (diff)
Fixes bug so that `%v` with modifiers doesn't compile. `%v` is not intended to work with modifiers because the meaning of modifiers is type-dependent and `%v` is intended to be used in situations where the type is not important. Please continue using if `%s` if you require format modifiers.
PiperOrigin-RevId: 472534916 Change-Id: I5838761b2b40cbc4344077f23d44b1e634e5bae3
Diffstat (limited to 'absl')
-rw-r--r--absl/strings/internal/str_format/checker.h4
-rw-r--r--absl/strings/str_format_test.cc2
2 files changed, 4 insertions, 2 deletions
diff --git a/absl/strings/internal/str_format/checker.h b/absl/strings/internal/str_format/checker.h
index 2542f31d..aeb9d48d 100644
--- a/absl/strings/internal/str_format/checker.h
+++ b/absl/strings/internal/str_format/checker.h
@@ -212,6 +212,10 @@ class ConvParser {
constexpr ConvParser ParseConversion() const {
char first_char = GetChar(format_, 0);
+ if (first_char == 'v' && *(format_.data() - 1) != '%') {
+ return SetError(true);
+ }
+
if (is_positional_) {
return VerifyPositional({ConsumeFront(format_), arg_position_},
first_char);
diff --git a/absl/strings/str_format_test.cc b/absl/strings/str_format_test.cc
index 7bffbb7a..4ac6aa27 100644
--- a/absl/strings/str_format_test.cc
+++ b/absl/strings/str_format_test.cc
@@ -291,8 +291,6 @@ TEST_F(FormatEntryPointTest, FormatStreamed) {
TEST_F(FormatEntryPointTest, FormatStreamedWithV) {
EXPECT_EQ("123", StrFormat("%v", FormatStreamed(123)));
- EXPECT_EQ(" 123", StrFormat("%5v", FormatStreamed(123)));
- EXPECT_EQ("123 ", StrFormat("%-5v", FormatStreamed(123)));
EXPECT_EQ("X", StrFormat("%v", FormatStreamed(streamed_test::X())));
EXPECT_EQ("123", StrFormat("%v", FormatStreamed(StreamFormat("%d", 123))));
}