From 856b5b51effc90991d7fa03f1a66d07aadf24225 Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Tue, 27 Feb 2024 19:11:34 +0100 Subject: [PATCH] secure children calls --- .../index/utils/VueJsComponentIndexUtil.java | 15 +++++++-------- .../de/espend/idea/vuejs/utils/VueJsUtil.java | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/espend/idea/vuejs/index/utils/VueJsComponentIndexUtil.java b/src/main/java/de/espend/idea/vuejs/index/utils/VueJsComponentIndexUtil.java index 136cefa..80dca16 100644 --- a/src/main/java/de/espend/idea/vuejs/index/utils/VueJsComponentIndexUtil.java +++ b/src/main/java/de/espend/idea/vuejs/index/utils/VueJsComponentIndexUtil.java @@ -21,10 +21,7 @@ import org.jetbrains.vuejs.index.VueFrameworkHandlerKt; import org.jetbrains.vuejs.lang.html.VueFile; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Daniel Espendiller @@ -82,10 +79,12 @@ public static Map> getSameDirectoryComponentsForIndex(@NotN Map directoryScope = new HashMap<>(); - VirtualFile[] vueFiles = Arrays.stream(vueFile - .getVirtualFile() - .getParent() - .getChildren()) + VirtualFile parent = vueFile.getVirtualFile().getParent(); + if (parent == null) { + return Collections.emptyMap(); + } + + VirtualFile[] vueFiles = Arrays.stream(parent.getChildren()) .filter(v -> "vue".equalsIgnoreCase(v.getExtension()) && !v.getName().equalsIgnoreCase(vueFile.getName())) .toArray(VirtualFile[]::new); diff --git a/src/main/java/de/espend/idea/vuejs/utils/VueJsUtil.java b/src/main/java/de/espend/idea/vuejs/utils/VueJsUtil.java index a9b9856..b5d9dbf 100644 --- a/src/main/java/de/espend/idea/vuejs/utils/VueJsUtil.java +++ b/src/main/java/de/espend/idea/vuejs/utils/VueJsUtil.java @@ -92,15 +92,18 @@ private void visitES6ImportedBinding(@NotNull String name, ES6ImportedBinding es // current directory scope - for (VirtualFile child : containingFile.getVirtualFile().getParent().getChildren()) { - String name = child.getName(); - if (!name.endsWith(".vue")) { - continue; - } + VirtualFile parent = containingFile.getVirtualFile().getParent(); + if (parent != null) { + for (VirtualFile child : parent.getChildren()) { + String name = child.getName(); + if (!name.endsWith(".vue")) { + continue; + } - String substring = name.substring(0, name.length() - 4); - components.putIfAbsent(substring, "./" + name); - components.putIfAbsent(VueJsUtil.convertToKebabCase(substring), "./" + name); + String substring = name.substring(0, name.length() - 4); + components.putIfAbsent(substring, "./" + name); + components.putIfAbsent(VueJsUtil.convertToKebabCase(substring), "./" + name); + } } return components;