Modify ↓
Ticket #149 (new defect)
Opened 3 years ago
Throws wrong ValueError exception on bad time stamps
| Reported by: | f_d_c_-alquiler@… | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | ValueError, YAMLError |
| Cc: |
Description
If a timestamp is badly formatted construct_yaml_timestamp() throws an uncaught ValueError? instead of yaml.YAMLError:
>>> yaml.safe_load("2009-13-11")
Traceback (most recent call last):
File "<pyshell#4>", line 2, in <module>
yaml.safe_load("2009-13-11")
File "C:\Python26\lib\site-packages\yaml\__init__.py", line 75, in safe_load
return load(stream, SafeLoader)
File "C:\Python26\lib\site-packages\yaml\__init__.py", line 58, in load
return loader.get_single_data()
File "C:\Python26\lib\site-packages\yaml\constructor.py", line 44, in get_single_data
return self.construct_document(node)
File "C:\Python26\lib\site-packages\yaml\constructor.py", line 48, in construct_document
data = self.construct_object(node)
File "C:\Python26\lib\site-packages\yaml\constructor.py", line 93, in construct_object
data = constructor(self, node)
File "C:\Python26\lib\site-packages\yaml\constructor.py", line 318, in construct_yaml_timestamp
return datetime.date(year, month, day)
ValueError: month must be in 1..12
Environment:
- Python 2.6.4 on Windows XP
- PyYAML-3.09-py2.5.exe
I think the function should include something like this:
try:
return datetime.date(year, month, day)
except ValueError:
raise ConstructorError(None,None,"inappropriate date value",node.start_mark)
Thank you.
Attachments
Note: See
TracTickets for help on using
tickets.
