From 64235468ce4e6081bdc5f3d45df5157a7b50cf37 Mon Sep 17 00:00:00 2001 From: Christian Holm Date: Sat, 9 Mar 2013 13:03:55 +0100 Subject: [PATCH] Handle invalid literals for start attribute --- html2text.py | 9 ++++++--- test/invalid_start.html | 8 ++++++++ test/invalid_start.md | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/invalid_start.html create mode 100644 test/invalid_start.md diff --git a/html2text.py b/html2text.py index 17528901..0d32f9c8 100755 --- a/html2text.py +++ b/html2text.py @@ -174,9 +174,12 @@ def google_fixed_width_font(style): def list_numbering_start(attrs): """extract numbering from list element attributes""" if 'start' in attrs: - return int(attrs['start']) - 1 - else: - return 0 + try: + return int(attrs['start']) - 1 + except ValueError: + pass + + return 0 class HTML2Text(HTMLParser.HTMLParser): def __init__(self, out=None, baseurl=''): diff --git a/test/invalid_start.html b/test/invalid_start.html new file mode 100644 index 00000000..0e49fe53 --- /dev/null +++ b/test/invalid_start.html @@ -0,0 +1,8 @@ + + +
    +
  1. The ol has an invalid start
  2. +
  3. This should just be ignored
  4. +
+ + \ No newline at end of file diff --git a/test/invalid_start.md b/test/invalid_start.md new file mode 100644 index 00000000..bed039c4 --- /dev/null +++ b/test/invalid_start.md @@ -0,0 +1,3 @@ + 1. The ol has an invalid start + 2. This should just be ignored +