masaccio/compact-json

The length computation of the last line in a multi-line is wrong

ZeroRin opened this issue · 1 comments

item_length + len(self.padded_comma_str) if not_last_item else 0

the current code results in a "tail" at the last line as the length of the last element is set to 0:
image

I think this line should be changed to

item_length + len(self.padded_comma_str)

which take into account the comma length no matter whether there will be a comma after the item. This could prevent such tail from happening when the max length is exactly 1 character less than the length of k elements with trailing comma. For example (I edited the bugged line to item_length + (len(self.padded_comma_str) if not_last_item else 0) before running the following code):
image

Many thanks for the patch. Latest PyPI has the change.