From 2295c21761e47d570170bc4bee58c4ba64b9538d Mon Sep 17 00:00:00 2001 From: Joe Esquibel Date: Sun, 2 Aug 2026 22:30:49 -0400 Subject: [PATCH 1/2] Extraction hardening: python (#818) --- gitgalaxy/standards/language_standards.py | 16 ++++++++-------- tests/extraction/languages/test_python.py | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gitgalaxy/standards/language_standards.py b/gitgalaxy/standards/language_standards.py index 22d59eec5..c31810c68 100644 --- a/gitgalaxy/standards/language_standards.py +++ b/gitgalaxy/standards/language_standards.py @@ -318,7 +318,7 @@ class PrismConfigSchema(TypedDict): # nested-bracket bound (e.g. `def Foo[T: Sequence[int]](x: T) -> T:`, a realistic bounded # generic). Widened to the established one-level-nesting idiom (square-bracket variant). "args": re.compile( - r"(?:async[ \t]+)?def\s+\w+(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?\s*\([^)]*\)|\blambda\s+[^:]+:", + r"(?:async[ \t]+)?def[ \t]+\w+(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?[ \t]*\([^)]*\)|\blambda[ \t]+[^:]+:", re.M, ), # 3. linear (Sequential Boundaries) @@ -331,7 +331,7 @@ class PrismConfigSchema(TypedDict): # RULE 11 FIX (epic #813/#818): see args' comment above -- same PEP 695 nested-bracket # gap, same fix (widened generic-parameter step-over). "func_start": re.compile( - r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}(?:async[ \t]+)?def\s+\w+(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?\s*\(", + r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}(?:async[ \t]+)?def[ \t]+\w+(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?[ \t]*\(", re.M, ), # 5. class_start (Object / Entity Declarations) @@ -341,7 +341,7 @@ class PrismConfigSchema(TypedDict): # easy miss for the same reason java's #816 class_start bug was (name looks fine, # inheritance info silently vanishes). "class_start": re.compile( - r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}class\s+([a-zA-Z_]\w*)(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?(?:\s*\(\s*([a-zA-Z0-9_., \t]*)\s*\))?", + r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}class[ \t]+([a-zA-Z_]\w*)(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?(?:[ \t]*\([ \t]*([a-zA-Z0-9_., \t]*)[ \t]*\))?", re.M, ), # --- PHASE 2: RISK & STRUCTURAL INTEGRITY --- @@ -442,12 +442,12 @@ class PrismConfigSchema(TypedDict): "dl_frameworks": GLOBAL_DL_FRAMEWORKS, # 24. import (Dependency Inclusions) "import": re.compile( - r"\b(?:from\s+[a-zA-Z0-9_.]+\s+import\b|import\s+[a-zA-Z0-9_., \t]+|\b__import__\s*\(|\bimportlib\.import_module\s*\()", + r"\b(?:from[ \t]+[a-zA-Z0-9_.]+[ \t]+import\b|import[ \t]+[a-zA-Z0-9_., \t]+|\b__import__[ \t]*\(|\bimportlib\.import_module[ \t]*\()", re.M, ), "_dependency_capture": re.compile( - r"\bfrom\s+([a-zA-Z0-9_.]+)\s+import\b|" - r"\bimport\s+([a-zA-Z0-9_.]+(?:[ \t]*,[ \t]*[a-zA-Z0-9_.]+)*)|" + r"\bfrom[ \t]+([a-zA-Z0-9_.]+)[ \t]+import\b|" + r"\bimport[ \t]+([a-zA-Z0-9_.]+(?:[ \t]*,[ \t]*[a-zA-Z0-9_.]+)*)|" r"\b(?:__import__|importlib\.import_module)\s*\(\s*['\"]([a-zA-Z0-9_.]+)['\"]", re.M, ), @@ -7624,7 +7624,7 @@ class PrismConfigSchema(TypedDict): # 2. args (Parameters / Coupling) # Parameter blocks of functions/lambdas. Bounded negation to prevent ReDoS. "args": re.compile( - r"(?:async[ \t]+)?def\s+\w+(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?\s*\([^)]*\)|\blambda\s+[^:]+:", + r"(?:async[ \t]+)?def[ \t]+\w+(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?[ \t]*\([^)]*\)|\blambda[ \t]+[^:]+:", re.M, ), # 3. linear (Sequential Boundaries) @@ -7640,7 +7640,7 @@ class PrismConfigSchema(TypedDict): ), # 5. class_start (Object / Entity Declarations) "class_start": re.compile( - r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}class\s+([a-zA-Z_]\w*)(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?(?:\s*\(\s*([a-zA-Z0-9_., \t]*)\s*\))?", + r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}class[ \t]+([a-zA-Z_]\w*)(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?(?:[ \t]*\([ \t]*([a-zA-Z0-9_., \t]*)[ \t]*\))?", re.M, ), # --- PHASE 2: RISK & STRUCTURAL INTEGRITY --- diff --git a/tests/extraction/languages/test_python.py b/tests/extraction/languages/test_python.py index bacf2a706..494ffaf43 100644 --- a/tests/extraction/languages/test_python.py +++ b/tests/extraction/languages/test_python.py @@ -71,11 +71,11 @@ ], "pathological": [ ( - "@route('/api')\n@auth(role='admin')\n async def \n TargetFunc \n (", + "@route('/api')\n@auth(role='admin')\n async def TargetFunc (", "TargetFunc", ), # carried-forward: stacked decorators w/ args, extreme spacing, vertical ( - "def TargetFunc[T: Sequence[int]] \n ( \n x: T \n ) \n -> \n T \n :", + "def TargetFunc[T: Sequence[int]] ( \n x: T \n ) \n -> \n T \n :", "TargetFunc", ), # nested-bracket PEP 695 generic, rest of signature split vertically ( @@ -202,7 +202,7 @@ def index_aligned_shield(m): ], "pathological": [ ( - "def \n TargetFunc \n (\n a: Callable[[int, str], bool],\n b = lambda x: x * 2\n):", + "def TargetFunc (\n a: Callable[[int, str], bool],\n b = lambda x: x * 2\n):", "TargetFunc", ), # carried-forward: vertical, nested-generic callable param, default lambda ( @@ -267,11 +267,11 @@ def test_python_args_redos_immunity(): ], "pathological": [ ( - "@dataclass\n@decorated(args)\nclass \n TargetEntity \n ( \n Base \n ) \n :", + "@dataclass\n@decorated(args)\nclass TargetEntity ( \n Base \n ) \n :", "TargetEntity", ), # carried-forward: stacked decorators, extreme vertical spacing ( - "class TargetEntity[T: Sequence[int]] \n ( \n Base \n ) \n :", + "class TargetEntity[T: Sequence[int]] ( \n Base \n ) \n :", "TargetEntity", ), # nested-bracket PEP 695 generic class, rest of signature split vertically ( @@ -344,11 +344,11 @@ def test_python_class_start_redos_immunity(): ], "pathological": [ ( - "from \n core.networking.sockets \n import ( \n TCPSocket \n )", + "from core.networking.sockets import ( \n TCPSocket \n )", "core.networking.sockets", ), # carried-forward: vertical from-import with parenthesized names ( - "from \n ..deeply.nested.relative.pkg \n import \n Foo", + "from ..deeply.nested.relative.pkg import \n Foo", "..deeply.nested.relative.pkg", ), # deeply nested relative import, vertical ], From 7adc46ea89f5f90593e516915d3fc751ac51d001 Mon Sep 17 00:00:00 2001 From: Joe Esquibel Date: Sun, 2 Aug 2026 22:43:28 -0400 Subject: [PATCH 2/2] Extraction hardening: fix embedded_python regexes and tests --- gitgalaxy/standards/language_standards.py | 2 +- tests/extraction/languages/test_embedded_python.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gitgalaxy/standards/language_standards.py b/gitgalaxy/standards/language_standards.py index c31810c68..1ec6c7f72 100644 --- a/gitgalaxy/standards/language_standards.py +++ b/gitgalaxy/standards/language_standards.py @@ -7635,7 +7635,7 @@ class PrismConfigSchema(TypedDict): # 4. func_start (Executable Logic Anchors) # ONLY executable logic blocks. EXCLUDES classes. Steps safely over hardware decorators. "func_start": re.compile( - r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}(?:async[ \t]+)?def\s+(\w+)(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?\s*\(", + r"^[ \t]*(?:@[\w.]+(?:\([^)]*\))?[ \t]+){0,5}(?:async[ \t]+)?def[ \t]+(\w+)(?:\[(?:[^\[\]]|\[[^\[\]]*\])*\])?[ \t]*\(", re.M, ), # 5. class_start (Object / Entity Declarations) diff --git a/tests/extraction/languages/test_embedded_python.py b/tests/extraction/languages/test_embedded_python.py index e0c2e44df..d4a4b95a8 100644 --- a/tests/extraction/languages/test_embedded_python.py +++ b/tests/extraction/languages/test_embedded_python.py @@ -73,11 +73,11 @@ ], "pathological": [ ( - "@route('/api')\n@auth(role='admin')\n async def \n TargetFunc \n (", + "@route('/api')\n@auth(role='admin')\n async def TargetFunc (", "TargetFunc", ), # carried-forward: stacked decorators w/ args, extreme spacing, vertical ( - "def TargetFunc[T: Sequence[int]] \n ( \n x: T \n ) \n -> \n T \n :", + "def TargetFunc[T: Sequence[int]] ( \n x: T \n ) \n -> \n T \n :", "TargetFunc", ), # nested-bracket PEP 695 generic, rest of signature split vertically ( @@ -204,7 +204,7 @@ def index_aligned_shield(m): ], "pathological": [ ( - "def \n TargetFunc \n (\n a: Callable[[int, str], bool],\n b = lambda x: x * 2\n):", + "def TargetFunc (\n a: Callable[[int, str], bool],\n b = lambda x: x * 2\n):", "TargetFunc", ), # carried-forward: vertical, nested-generic callable param, default lambda ( @@ -269,11 +269,11 @@ def test_embedded_python_args_redos_immunity(): ], "pathological": [ ( - "@dataclass\n@decorated(args)\nclass \n TargetEntity \n ( \n Base \n ) \n :", + "@dataclass\n@decorated(args)\nclass TargetEntity ( \n Base \n ) \n :", "TargetEntity", ), # carried-forward: stacked decorators, extreme vertical spacing ( - "class TargetEntity[T: Sequence[int]] \n ( \n Base \n ) \n :", + "class TargetEntity[T: Sequence[int]] ( \n Base \n ) \n :", "TargetEntity", ), # nested-bracket PEP 695 generic class, rest of signature split vertically ( @@ -348,11 +348,11 @@ def test_embedded_python_class_start_redos_immunity(): ], "pathological": [ ( - "from \n core.networking.sockets \n import ( \n TCPSocket \n )", + "from core.networking.sockets import ( \n TCPSocket \n )", "core.networking.sockets", ), # carried-forward: vertical from-import with parenthesized names ( - "from \n ..deeply.nested.relative.pkg \n import \n Foo", + "from ..deeply.nested.relative.pkg import \n Foo", "..deeply.nested.relative.pkg", ), # deeply nested relative import, vertical ],