Closed eagleDiego closed 1 year ago
Ok I see the issue. One possible solution would be to exclude prior tag matches from the regex so "C) "
wouldn't match twice. I think the fastest way would be to create additional compiled regexes based on the most recent tag letter. The letters follow a predictable order, so it shouldn't create too much overhead.
KEY_PATTERNS = {
None: re.compile(r"[A-GQ]\) "),
"Q": re.compile(r"[A-G]\) "),
"A": re.compile(r"[B-G]\) "),
...
}
match = KEY_PATTERNS[tag].search(text)
I've implemented the fix above as well as adding a boundary check to the regex to make it more precise. In addition to fixing the report above, it also fixed bodies containing "(OBSTACLE)"
that was previously being cut off in the test suite. Version 1.8.3 will contain the fix and go out soon.
I came across a NOTAM that was throwing an error:
The body of the NOTAM (under tag
E)
) contains text that is the same as a tag, theC)
inPOINT C) 'FOLLOW-ME
.avwx/current/notam.py
doesn't allow for this to happen.I solved the error by checking that the tag's content is being set for the first time (in theory, arbitrary text should only appear after the header, so this should be relatively safe).
My proposed edit below:
However, one issue remains because the original string is being sliced every time the tags are found, the NOTAM body is cut just before the
C)
in the text.I'm no RegEx wizard, so there might be a more succinct way of solving this problem by altering the RegEx that matches the tags.