# HG changeset patch
# Parent e75d9104b1af854ddeeb08070adbcd39fdc4ec53
Handle invalid time input more gracefully.
diff --git a/trac/ticket/web_ui.py b/trac/ticket/web_ui.py
|
a
|
b
|
|
| 706 | 706 | fields.pop('checkbox_' + each, None) # See Ticket.populate() |
| 707 | 707 | for field, value in fields.iteritems(): |
| 708 | 708 | if field in ticket.time_fields: |
| 709 | | fields[field] = user_time(req, parse_date, value) \ |
| 710 | | if value else None |
| | 709 | try: |
| | 710 | fields[field] = user_time(req, parse_date, value) \ |
| | 711 | if value else None |
| | 712 | except TracError, e: |
| | 713 | # Handle bad user input for custom time fields gracefully. |
| | 714 | if field in ticket.custom_fields: |
| | 715 | # Leave it to _validate_ticket() to complain. |
| | 716 | fields[field] = value |
| | 717 | else: |
| | 718 | raise TracError(e) |
| 711 | 719 | ticket.populate(fields) |
| 712 | 720 | # special case for updating the Cc: field |
| 713 | 721 | if 'cc_update' in req.args: |
| … |
… |
|
| 1202 | 1210 | # Shouldn't happen in "normal" circumstances, hence not a warning |
| 1203 | 1211 | raise InvalidTicket(_("Invalid comment threading identifier")) |
| 1204 | 1212 | |
| 1205 | | # FIXME: Validate time field content |
| | 1213 | # Validate time field content |
| | 1214 | for field in ticket.time_fields: |
| | 1215 | value = ticket[field] |
| | 1216 | if not (field in ticket.std_fields or \ |
| | 1217 | isinstance(value, datetime)): |
| | 1218 | try: |
| | 1219 | ticket.values[field] = user_time(req, parse_date, value) \ |
| | 1220 | if value else None |
| | 1221 | except TracError, e: |
| | 1222 | # Degrade TracError to warning. |
| | 1223 | add_warning(req, e) |
| | 1224 | ticket.values[field] = value |
| | 1225 | valid = False |
| 1206 | 1226 | |
| 1207 | 1227 | # Custom validation rules |
| 1208 | 1228 | for manipulator in self.ticket_manipulators: |
| … |
… |
|
| 1681 | 1701 | return rendered |
| 1682 | 1702 | |
| 1683 | 1703 | def _render_time_field(self, req, value, format, relative=False): |
| | 1704 | if value and not isinstance(value, datetime): |
| | 1705 | # Return invalid timestamps unchanged. |
| | 1706 | return u'' if 'None' else unicode(value) |
| 1684 | 1707 | format = format or 'datetime' |
| 1685 | 1708 | if format == 'age' and relative: |
| 1686 | 1709 | return pretty_timedelta(value) if value else '' |