Fix bug discovered by John W. Shipman -- when the width of a format
specifier came from an int expression instead of a constant in the format, a negative width was truncated to zero instead of taken to mean the same as that negative constant plugged into the format. E.g. "(%*s)" % (-5, "foo") yielded "(foo)" while "(%-5s)" yields "(foo )". Now both yield the latter -- like sprintf() in C.
This commit is contained in:
parent
729afc1dff
commit
98c9eba945
|
@ -832,8 +832,10 @@ PyString_Format(format, args)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
width = PyInt_AsLong(v);
|
width = PyInt_AsLong(v);
|
||||||
if (width < 0)
|
if (width < 0) {
|
||||||
width = 0;
|
flags |= F_LJUST;
|
||||||
|
width = -width;
|
||||||
|
}
|
||||||
if (--fmtcnt >= 0)
|
if (--fmtcnt >= 0)
|
||||||
c = *fmt++;
|
c = *fmt++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue