diff --git a/AUTHORS b/AUTHORS index d645dfc9..bf044b70 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,6 +8,7 @@ Here is a list of past and present much-appreciated contributors: Andrii Soldatenko Benjamin Wohlwend Bruno Soares + Charles Tonneslan Claude Paroz Daniel Santos Egor Osokin diff --git a/src/tablib/core.py b/src/tablib/core.py index 74f0dc54..4caec910 100644 --- a/src/tablib/core.py +++ b/src/tablib/core.py @@ -638,7 +638,7 @@ def add_formatter(self, col, handler): else: raise KeyError - if col is None or col <= self.width: + if col is None or col < self.width: self._formatters.append((col, handler)) else: raise InvalidDatasetIndex diff --git a/tests/test_tablib.py b/tests/test_tablib.py index 26224167..3547f8e5 100755 --- a/tests/test_tablib.py +++ b/tests/test_tablib.py @@ -19,7 +19,7 @@ import tablib from tablib.core import Row, detect_format -from tablib.exceptions import UnsupportedFormat +from tablib.exceptions import InvalidDatasetIndex, UnsupportedFormat from tablib.formats import registry try: @@ -603,6 +603,11 @@ def _formatter(cell_value): # Test once more as the result should be the same self.assertEqual(self.founders.dict, expected) + def test_formatter_invalid_column_index(self): + """Registering a formatter on an out-of-range index is rejected.""" + with self.assertRaises(InvalidDatasetIndex): + self.founders.add_formatter(self.founders.width, str) + def test_formatters_all_cols(self): """ Passing None as first add_formatter param apply formatter to all columns.