Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(php): bound namespace trimming

Hiro-Chiba83079ff3dca7
diff --git a/core-ingestion/src/__tests__/resolveEdges.test.ts b/core-ingestion/src/__tests__/resolveEdges.test.ts
index c4638e3f..6de0405a 100644
--- a/core-ingestion/src/__tests__/resolveEdges.test.ts
+++ b/core-ingestion/src/__tests__/resolveEdges.test.ts
@@ -275,6 +275,25 @@ class User { public function save(): void {} }
expect(resolveEdges([consumer, wrong])).toEqual([]);
});
+ it('normalizes repeated namespace separators without regex backtracking', () => {
+ const provider = parseFile(
+ '/repo/src/Vendor/User.php',
+ '<?php namespace Vendor\\Package; class User {}',
+ )!;
+ const entity = provider.entities.find((candidate) => candidate.name === 'User')!;
+ entity.packageScope = `${'\\'.repeat(4096)}Vendor\\Package${'\\'.repeat(4096)}`;
+ const consumer = parseFile(
+ '/repo/src/Consumer.php',
+ '<?php use Vendor\\Package\\User; function run(User $user): void { new User(); }',
+ )!;
+
+ const edges = resolveEdges([consumer, provider]).filter(
+ (edge) => edge.dstFilePath === '/repo/src/Vendor/User.php',
+ );
+
+ expect(edges).toHaveLength(3);
+ });
+
it('resolves PHP class imports, references, and calls by exact FQCN', () => {
const consumer = parseFile(
'/repo/Consumer.php',
diff --git a/core-ingestion/src/index.ts b/core-ingestion/src/index.ts
index 217bea9c..5ee6b342 100644
--- a/core-ingestion/src/index.ts
+++ b/core-ingestion/src/index.ts
@@ -2876,11 +2876,20 @@ function qualifiedKey(e: ParsedEntity): string {
const PHP_TYPE_KINDS = new Set(['class', 'interface', 'trait', 'enum']);
+function trimPhpNamespace(namespace: string | undefined): string {
+ if (!namespace) return '';
+ let start = 0;
+ let end = namespace.length;
+ while (start < end && namespace.charCodeAt(start) === 92) start++;
+ while (end > start && namespace.charCodeAt(end - 1) === 92) end--;
+ return namespace.slice(start, end);
+}
+
function phpTypeFqcn(entity: ParsedEntity): string | undefined {
if (entity.language !== SupportedLanguages.PHP || !PHP_TYPE_KINDS.has(entity.kind) || entity.container) {
return undefined;
}
- const namespace = entity.packageScope?.replace(/^\\+|\\+$/g, '');
+ const namespace = trimPhpNamespace(entity.packageScope);
return `${namespace ? `${namespace}\\` : ''}${entity.name}`.toLowerCase();
}