Skip to content

Commit 9e4d8e6

Browse files
committed
secure some long template filenames to be not indexed
1 parent 310e78d commit 9e4d8e6

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/ServiceIndexUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.jetbrains.yaml.psi.YAMLFile;
3737

3838
import java.nio.file.FileSystems;
39+
import java.nio.file.InvalidPathException;
3940
import java.nio.file.Paths;
4041
import java.util.*;
4142
import java.util.regex.PatternSyntaxException;
@@ -302,7 +303,7 @@ private static boolean isMatchingGlobResource(@NotNull String glob, @NotNull Str
302303
// nested types not support by java glob implementation so just catch the exception: "../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,Service/{IspConfiguration,DataCollection}}"
303304
try {
304305
return FileSystems.getDefault().getPathMatcher("glob:" + glob).matches(Paths.get(path));
305-
} catch (PatternSyntaxException e) {
306+
} catch (PatternSyntaxException | InvalidPathException e) {
306307
return false;
307308
}
308309
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/PhpTwigTemplateUsageStubIndex.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public DataIndexer<String, TemplateUsage, FileContent> getIndexer() {
5050
PhpMethodVariableResolveUtil.visitRenderTemplateFunctions(psiFile, triple -> {
5151
String templateName = triple.getFirst();
5252

53+
if (templateName.length() > 255) {
54+
return;
55+
}
56+
5357
if(!items.containsKey(templateName)) {
5458
items.put(templateName, new HashSet<>());
5559
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/TwigExtendsStubIndex.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ public DataIndexer<String, Void, FileContent> getIndexer() {
4444
return map;
4545
}
4646

47-
TwigUtil.visitTemplateExtends((TwigFile) psiFile, pair ->
48-
map.put(TwigUtil.normalizeTemplateName(pair.getFirst()), null)
49-
);
47+
TwigUtil.visitTemplateExtends((TwigFile) psiFile, pair -> {
48+
String first = pair.getFirst();
49+
if (first.length() < 255) {
50+
map.put(TwigUtil.normalizeTemplateName(first), null);
51+
}
52+
});
5053

5154
return map;
5255
};

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/TwigIncludeStubIndex.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ public DataIndexer<String, Void, FileContent> getIndexer() {
4444
return map;
4545
}
4646

47-
TwigUtil.visitTemplateIncludes((TwigFile) psiFile, templateInclude ->
48-
map.put(TwigUtil.normalizeTemplateName(templateInclude.getTemplateName()), null)
49-
);
47+
TwigUtil.visitTemplateIncludes((TwigFile) psiFile, templateInclude -> {
48+
if (templateInclude.getTemplateName().length() < 255) {
49+
map.put(TwigUtil.normalizeTemplateName(templateInclude.getTemplateName()), null);
50+
}
51+
});
52+
5053

5154
return map;
5255
};

0 commit comments

Comments
 (0)