Ignore:
Timestamp:
18 Jan 2018, 07:34:42 (7 years ago)
Author:
Henrik Bettermann
Message:

Do not allow uploading data with trailing whitespaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py

    r13537 r14939  
    756756
    757757def check_csv_charset(iterable):
    758     """Check contents of `iterable` regarding valid CSV encoding.
     758    """Check contents of `iterable` regarding valid CSV encoding and
     759    trailing whitespaces in data.
    759760
    760761    `iterable` is expected to be an iterable on _rows_ (not
     
    764765
    765766    Returns line num of first illegal char or ``None``. Line nums
    766     start counting with 1 (not zero).
     767    start counting with 1 (not zero). Returns -1 if data contain
     768    trailing whitespaces.
    767769    """
    768770    linenum = 1
     
    771773        for row in reader:
    772774            linenum += 1
     775            for value in row.values():
     776                if value.endswith(' '):
     777                    return -1
    773778    except UnicodeDecodeError:
    774779        return linenum
Note: See TracChangeset for help on using the changeset viewer.