Skip to content

IndexError: string index out of range in Template.normal_name() #105

@winstontsai

Description

@winstontsai

I encountered an IndexError in the Template.normal_name function while running my bot. I don't have the actual example that caused this, but I have reproduced an example of what I think happened:

>>> x = wtp.Template('{{Template: | hi=bye}}')
>>> x.normal_name(capitalize=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/winston/projects/IndentBot/venv/lib/python3.9/site-packages/wikitextparser/_template.py", line 95, in normal_name
    n0 = name[0]
IndexError: string index out of range

One fix would be to change this code:

if capitalize:
    # Use uppercase for the first letter
    n0 = name[0]
    if n0.islower():
        name = n0.upper() + name[1:]

to

if capitalize:
    # Use uppercase for the first letter
    name = name[:1].upper() + name[1:]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions