summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/printf.c2
-rwxr-xr-xtestsuite/printf.tests10
2 files changed, 11 insertions, 1 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c
index dd94c8ade..2e672d15f 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -313,7 +313,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
}
break;
}
- if (*f && strchr("-+ #", *f)) {
+ while (*f && strchr("-+ #0", *f)) {
++f;
++direc_length;
}
diff --git a/testsuite/printf.tests b/testsuite/printf.tests
index 050edef71..728bbf4bf 100755
--- a/testsuite/printf.tests
+++ b/testsuite/printf.tests
@@ -143,4 +143,14 @@ testing "printf aborts on %r" \
"printf: %r: invalid format\n""1\n" \
"" ""
+testing "printf treats leading 0 as flag" \
+ "${bb}printf '%0*d\n' 2 1 2>&1; echo \$?" \
+ "01\n""0\n" \
+ "" ""
+
+testing "printf handles multiple flags" \
+ "${bb}printf '%0 d\n' 2 2>&1; echo \$?" \
+ " 2\n""0\n" \
+ "" ""
+
exit $FAILCOUNT