Ticket #34000: 4375ad983f2adbfdd091a1e92a847dd108d04c02.patch

File 4375ad983f2adbfdd091a1e92a847dd108d04c02.patch, 931 bytes (added by Jimmy Angelakos, 2 years ago)

proposed fix patch

  • django/utils/numberformat.py

    From 4375ad983f2adbfdd091a1e92a847dd108d04c02 Mon Sep 17 00:00:00 2001
    From: Jimmy Angelakos <vyruss@hellug.gr>
    Date: Fri, 9 Sep 2022 23:35:54 +0100
    Subject: [PATCH] Fix numberformat.py "string index out of range"
    
    When `if str_number[0] == "-"` encounters a number field that's null when formatting for the admin `list_display` this causes an `IndexError: string index out of range`
    ---
     django/utils/numberformat.py | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py
    index 488d6a77cdd1..e952af3fdc6d 100644
    a b def format(  
    6868            str_number = "{:f}".format(number)
    6969    else:
    7070        str_number = str(number)
    71     if str_number[0] == "-":
     71    if str_number and str_number[0] == "-":
    7272        sign = "-"
    7373        str_number = str_number[1:]
    7474    # decimal part
Back to Top