diff options
-rw-r--r-- | editors/awk.c | 9 | ||||
-rwxr-xr-x | testsuite/awk.tests | 6 | ||||
-rwxr-xr-x | testsuite/printf.tests | 5 |
3 files changed, 19 insertions, 1 deletions
diff --git a/editors/awk.c b/editors/awk.c index 3adbca7aa..f7b8ef0d3 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -2346,8 +2346,15 @@ static char *awk_printf(node *n, size_t *len) | |||
2346 | size_t slen; | 2346 | size_t slen; |
2347 | 2347 | ||
2348 | s = f; | 2348 | s = f; |
2349 | while (*f && (*f != '%' || *++f == '%')) | 2349 | while (*f && *f != '%') |
2350 | f++; | 2350 | f++; |
2351 | c = *++f; | ||
2352 | if (c == '%') { /* double % */ | ||
2353 | slen = f - s; | ||
2354 | s = xstrndup(s, slen); | ||
2355 | f++; | ||
2356 | goto tail; | ||
2357 | } | ||
2351 | while (*f && !isalpha(*f)) { | 2358 | while (*f && !isalpha(*f)) { |
2352 | if (*f == '*') | 2359 | if (*f == '*') |
2353 | syntax_error("%*x formats are not supported"); | 2360 | syntax_error("%*x formats are not supported"); |
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index dc2ae2e11..bcaafe8fd 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
@@ -463,4 +463,10 @@ testing "awk \"cmd\" | getline" \ | |||
463 | "HELLO\n" \ | 463 | "HELLO\n" \ |
464 | '' '' | 464 | '' '' |
465 | 465 | ||
466 | # printf %% should print one % (had a bug where it didn't) | ||
467 | testing 'awk printf %% prints one %' \ | ||
468 | "awk 'BEGIN { printf \"%%\n\" }'" \ | ||
469 | "%\n" \ | ||
470 | '' '' | ||
471 | |||
466 | exit $FAILCOUNT | 472 | exit $FAILCOUNT |
diff --git a/testsuite/printf.tests b/testsuite/printf.tests index 34a65926e..050edef71 100755 --- a/testsuite/printf.tests +++ b/testsuite/printf.tests | |||
@@ -79,6 +79,11 @@ testing "printf understands %Ld" \ | |||
79 | "-5\n""0\n" \ | 79 | "-5\n""0\n" \ |
80 | "" "" | 80 | "" "" |
81 | 81 | ||
82 | testing "printf understands %%" \ | ||
83 | "${bb}printf '%%\n' 2>&1; echo \$?" \ | ||
84 | "%\n""0\n" \ | ||
85 | "" "" | ||
86 | |||
82 | testing "printf handles positive numbers for %d" \ | 87 | testing "printf handles positive numbers for %d" \ |
83 | "${bb}printf '%d\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \ | 88 | "${bb}printf '%d\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \ |
84 | "3\n"\ | 89 | "3\n"\ |