---
title: "pytimeparse: sign regex fix in Python | VulCode"
description: "A fix to pytimeparse in Python: the character class [+|-] also matched a pipe, so |5m parsed as 300 seconds. Such input now returns None, as it should."
url: "https://vulcode.com/en/opensource/contributions/pytimeparse"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

wroberts/pytimeparse

# pytimeparse

A small Python module that turns time expressions such as 1h30m or 1:24 into a number of seconds.

[See the repository](https://github.com/wroberts/pytimeparse) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Python
- **GitHub stars**: 296
- **Merged changes**: 1

## What we changed

The sign character class no longer accidentally matches a pipe, so input starting with | is rejected instead of being parsed silently.

### What this work shows

- Regular expressions in Python

- Parser input validation

- Negative tests with unittest

What was broken

### A pipe passed for a sign

The sign pattern was [+|-], and inside a character class | is a plain character. parse('|5m') returned 300 and parse('|1:24') returned 84 instead of rejecting the bad input.

How we fixed it

### A character class with only plus and minus

The pattern is now [+-], so the pipe stays in the string, no time format matches it and timeparse returns None. Tests cover |5m, | 5m and |1:24.

[#33](https://github.com/wroberts/pytimeparse/pull/33)

## Merged change

1 3 October 2026

- [01 #33Merged 3 October 2026 Fix sign character class accidentally matching a pipe `|`](https://github.com/wroberts/pytimeparse/pull/33)

## What it taught us

Inside a regex character class a pipe is a literal, not an alternation. A parser that silently accepts bad input is worse than one that rejects it, so we also test what a parser should refuse.

[More about this technology: Python](https://vulcode.com/en/technologies/python)

## Other projects we write code for

- [**more-itertools** Python · 4,106 stars A Python library with more routines for operating on iterables, beyond the itertools module.](https://vulcode.com/en/opensource/contributions/more-itertools)

- [**funcy** Python · 3,507 stars A collection of practical functional tools for Python, including helpers for sequences, collections and iterators.](https://vulcode.com/en/opensource/contributions/funcy)

- [**python-benedict** Python · 1,606 stars A Python dict subclass with key path access and built-in reading and writing of many formats, such as JSON, YAML, TOML and CSV.](https://vulcode.com/en/opensource/contributions/python-benedict)

- [**pydash** Python · 1,449 stars A Python utility library modelled on Lo-Dash from JavaScript. It offers ready-made operations on lists, dicts and strings in a functional style.](https://vulcode.com/en/opensource/contributions/pydash)

- [**pydantic-extra-types** Python · 345 stars Extra types for data validation in Pydantic, the popular Python library: MAC addresses, time zones, semantic versions, ULIDs and many more.](https://vulcode.com/en/opensource/contributions/pydantic-extra-types)

- [**Node.js** JavaScript · 123,955 stars The JavaScript runtime built on V8 that runs servers, command line tools and front-end build pipelines. It ships a built-in node:sqlite module for working with SQLite databases.](https://vulcode.com/en/opensource/contributions/nodejs)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
