Spaces:
Sleeping
Sleeping
Commit ·
8c862c5
1
Parent(s): 5ea2e30
Improve: More robust case-insensitive XML parsing for small models
Browse files
commitguard_env/parse_action.py
CHANGED
|
@@ -10,7 +10,9 @@ _TAG_RE = re.compile(r"<(?P<tag>[a-zA-Z_]+)>(?P<val>.*?)</(?P=tag)>", re.DOTALL)
|
|
| 10 |
|
| 11 |
|
| 12 |
def _first(tag: str, text: str) -> Optional[str]:
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
if not m:
|
| 15 |
return None
|
| 16 |
return m.group(1).strip()
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
def _first(tag: str, text: str) -> Optional[str]:
|
| 13 |
+
# Robust case-insensitive search with optional whitespace inside tags
|
| 14 |
+
pattern = rf"<[ \t]*{re.escape(tag)}[ \t]*>(.*?)</[ \t]*{re.escape(tag)}[ \t]*>"
|
| 15 |
+
m = re.search(pattern, text, flags=re.DOTALL | re.IGNORECASE)
|
| 16 |
if not m:
|
| 17 |
return None
|
| 18 |
return m.group(1).strip()
|