Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

No proper validation for month in Calendar Module #126476

Closed
Labels
3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@gugupy

Description

@gugupy

Bug report

Bug description:

In the calendar module,IllegalMonthError is not handled properly. For months greater than 12, an IndexError is raised instead.

formatmonthname do not raise IndexError for negative integer because list support negative integer indexing.

>>>importcalendar>>>calendar.month(2024,-1)Traceback (mostrecentcalllast):File"<python-input-12>",line1,in<module>calendar.month(2024,-1)~~~~~~~~~~~~~~^^^^^^^^^^File"/Users/gugu/Code/cpython/Lib/calendar.py",line395,informatmonthforweekinself.monthdays2calendar(theyear,themonth):~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^File"/Users/gugu/Code/cpython/Lib/calendar.py",line284,inmonthdays2calendardays=list(self.itermonthdays2(year,month))File"/Users/gugu/Code/cpython/Lib/calendar.py",line240,initermonthdays2fori,dinenumerate(self.itermonthdays(year,month),self.firstweekday):~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/Users/gugu/Code/cpython/Lib/calendar.py",line228,initermonthdaysday1,ndays=monthrange(year,month)~~~~~~~~~~^^^^^^^^^^^^^File"/Users/gugu/Code/cpython/Lib/calendar.py",line165,inmonthrangeraiseIllegalMonthError(month)calendar.IllegalMonthError:badmonthnumber-1;mustbe1-12>>>calendar.month(2024,13)Traceback (mostrecentcalllast):File"<python-input-13>",line1,in<module>calendar.month(2024,13)~~~~~~~~~~~~~~^^^^^^^^^^File"/Users/gugu/Code/cpython/Lib/calendar.py",line390,informatmonths=self.formatmonthname(theyear,themonth,7* (w+1)-1)File"/Users/gugu/Code/cpython/Lib/calendar.py",line373,informatmonthnames=month_name[themonth]~~~~~~~~~~^^^^^^^^^^File"/Users/gugu/Code/cpython/Lib/calendar.py",line103,in__getitem__funcs=self._months[i]~~~~~~~~~~~~^^^IndexError:listindexoutofrange

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp