summaryrefslogtreecommitdiffstats
path: root/Python/formatter_unicode.c
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2014-04-14 15:55:10 (GMT)
committerEric V. Smith <eric@trueblade.com>2014-04-14 15:55:10 (GMT)
commit2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b (patch)
tree236cd53e05426767821a0473f31097e54fdf2032 /Python/formatter_unicode.c
parent70d92a96ab47e0b8b9cb78d437b3761296f815ed (diff)
downloadcpython-2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b.zip
cpython-2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b.tar.gz
cpython-2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b.tar.bz2
Issue #12546: Allow \x00 as a fill character for builtin type __format__ methods.
Diffstat (limited to 'Python/formatter_unicode.c')
-rw-r--r--Python/formatter_unicode.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
index 0a3cc59..e3a8149 100644
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -156,8 +156,9 @@ parse_internal_render_format_spec(PyObject *format_spec,
Py_ssize_t consumed;
int align_specified = 0;
+ int fill_char_specified = 0;
- format->fill_char = '\0';
+ format->fill_char = ' ';
format->align = default_align;
format->alternate = 0;
format->sign = '\0';
@@ -171,6 +172,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
if (end-pos >= 2 && is_alignment_token(READ_spec(pos+1))) {
format->align = READ_spec(pos+1);
format->fill_char = READ_spec(pos);
+ fill_char_specified = 1;
align_specified = 1;
pos += 2;
}
@@ -194,7 +196,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
}
/* The special case for 0-padding (backwards compat) */
- if (format->fill_char == '\0' && end-pos >= 1 && READ_spec(pos) == '0') {
+ if (!fill_char_specified && end-pos >= 1 && READ_spec(pos) == '0') {
format->fill_char = '0';
if (!align_specified) {
format->align = '=';
@@ -784,9 +786,7 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format,
goto done;
/* Write into that space. First the padding. */
- result = fill_padding(writer, len,
- format->fill_char=='\0'?' ':format->fill_char,
- lpad, rpad);
+ result = fill_padding(writer, len, format->fill_char, lpad, rpad);
if (result == -1)
goto done;
@@ -956,8 +956,7 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format,
/* Populate the memory. */
result = fill_number(writer, &spec,
tmp, inumeric_chars, inumeric_chars + n_digits,
- tmp, prefix,
- format->fill_char == '\0' ? ' ' : format->fill_char,
+ tmp, prefix, format->fill_char,
&locale, format->type == 'X');
done:
@@ -1104,8 +1103,7 @@ format_float_internal(PyObject *value,
/* Populate the memory. */
result = fill_number(writer, &spec,
unicode_tmp, index, index + n_digits,
- NULL, 0,
- format->fill_char == '\0' ? ' ' : format->fill_char,
+ NULL, 0, format->fill_char,
&locale, 0);
done:
@@ -1311,8 +1309,7 @@ format_complex_internal(PyObject *value,
/* Populate the memory. First, the padding. */
result = fill_padding(writer,
n_re_total + n_im_total + 1 + add_parens * 2,
- format->fill_char=='\0' ? ' ' : format->fill_char,
- lpad, rpad);
+ format->fill_char, lpad, rpad);
if (result == -1)
goto done;