Repository: python-metar/python-metar

Issue:
Parser allows invalid format of temperature group
The regex for the temperature group allows an arbitrary number (but at least 1) of digits, both for temperature and dewpoint:
https://github.com/python-metar/python-metar/blob/96f6b98ce685b37c7d5e438fa2d5e2648e56d0b0/metar/Metar.py#L87-L90

However, the [Manual on Codes](https://library.wmo.int/doc_num.php?explnum_id=10235) gives the format of the temperature group as T'T'/T'<sub>d</sub>T'<sub>d</sub> in 15.11, calling for exactly 2 digits.

Consequently, the following report should raise an error instead of parsing a temperature of 201°C (which clearly is a typo in this context considering the reports before/after this one).
> METAR EDDM 022150Z 26006KT CAVOK 201/16 Q1018 NOSIG


Discussion:

Patch:
diff --git a/metar/Metar.py b/metar/Metar.py
index cf6026f..8da571d 100644
--- a/metar/Metar.py
+++ b/metar/Metar.py
@@ -85,8 +85,8 @@ SKY_RE = re.compile(
     re.VERBOSE,
 )
 TEMP_RE = re.compile(
-    r"""^(?P<temp>(M|-)?\d+|//|XX|MM)/
-        (?P<dewpt>(M|-)?\d+|//|XX|MM)?\s+""",
+    r"""^(?P<temp>(M|-)?\d{1,2}|//|XX|MM)/
+        (?P<dewpt>(M|-)?\d{1,2}|//|XX|MM)?\s+""",
     re.VERBOSE,
 )
 PRESS_RE = re.compile(


Test patch:
diff --git a/test/test_metar.py b/test/test_metar.py
index ed43504..9bafe17 100644
--- a/test/test_metar.py
+++ b/test/test_metar.py
@@ -653,3 +653,7 @@ def test_cor_auto_mod():
     m = Metar.Metar(code, year=2019)
 
     assert m.mod == 'COR AUTO'
+
+
+def test_issue136_temperature():
+    raisesParserError("METAR EDDM 022150Z 26006KT CAVOK 201/16")