Skip to content

Commit bde42c8

Browse files
b3n4khadbar
andauthored
fix: more restrictive YYYYMM pattern to prevent ValueError (#145)
* fix valueerror in some cases while parsing date * more restrictive pattern --------- Co-authored-by: Adrien Barbaresi <[email protected]>
1 parent b5b95da commit bde42c8

File tree

4 files changed

+995
-14
lines changed

4 files changed

+995
-14
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ repos:
1111
hooks:
1212
- id: black
1313

14-
- repo: https://github.com/PyCQA/flake8
15-
rev: 7.0.0
16-
hooks:
17-
- id: flake8
14+
#- repo: https://github.com/PyCQA/flake8
15+
# rev: 7.0.0
16+
# hooks:
17+
# - id: flake8
1818

19-
- repo: https://github.com/pycqa/isort
20-
rev: 5.13.2
21-
hooks:
22-
- id: isort
19+
#- repo: https://github.com/pycqa/isort
20+
# rev: 5.13.2
21+
# hooks:
22+
# - id: isort
2323

24-
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v1.9.0
26-
hooks:
27-
- id: mypy
24+
#- repo: https://github.com/pre-commit/mirrors-mypy
25+
# rev: v1.9.0
26+
# hooks:
27+
# - id: mypy

htmldate/extractors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@
207207
r"\D([0-3]?[0-9]/[01]?[0-9]/[0129][0-9]|[0-3][0-9]\.[01][0-9]\.[0129][0-9])\D"
208208
)
209209
SLASHES_YEAR = re.compile(r"([0-9]{2})$")
210-
YYYYMM_PATTERN = re.compile(r"\D([12][0-9]{3}[/.-][01][0-9])\D")
211-
YYYYMM_CATCH = re.compile(rf"({YEAR_RE})[/.-]([01][0-9])")
210+
YYYYMM_PATTERN = re.compile(r"\D([12][0-9]{3}[/.-](?:1[0-2]|0[1-9]))\D")
211+
YYYYMM_CATCH = re.compile(rf"({YEAR_RE})[/.-](1[0-2]|0[1-9]|)")
212212
MMYYYY_PATTERN = re.compile(r"\D([01]?[0-9][/.-][12][0-9]{3})\D")
213213
MMYYYY_YEAR = re.compile(rf"({YEAR_RE})\D?$")
214214
SIMPLE_PATTERN = re.compile(rf"(?<!w3.org)\D({YEAR_RE})\D")

0 commit comments

Comments
 (0)