Skip to content

Commit cf30eb1

Browse files
committed
#13 Fix, add a try-catch on getting file by path with LocalFileSystem
As it appears that it throws an exception on invalid paths like one having "//.." in it
1 parent 0e852a8 commit cf30eb1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/org/klesun/deep_js_completion/entry/PathStrGoToDecl.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ object PathStrGoToDecl {
2020
.flatMap(f => Option(f.getContainingDirectory))
2121
.flatMap(f => Option(f.getVirtualFile))
2222
.map(f => f.getPath + "/" + relPath + (if (relPath.matches(".*\\.[a-zA-Z0-9]+$")) "" else ".js"))
23-
.flatMap(fullPath => Option(LocalFileSystem.getInstance.findFileByPath(fullPath)))
23+
.flatMap(fullPath => {
24+
try {
25+
Option(LocalFileSystem.getInstance.findFileByPath(fullPath))
26+
} catch {
27+
case exc: Throwable => None
28+
}
29+
})
2430
.flatMap(f => Option(PsiManager.getInstance(caretFile.getProject).findFile(f)))
2531
}
2632

tests/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

2+
let SomeInvalidPathModule = require('.//../asd.js');
23
let SomeCjsModule = require('./SomeCjsModule.js');
34

5+
// tried to reproduce #13, did not succeed, but will add the try-catch nevertheless
6+
SomeInvalidPathModule.asd;
7+
48
SomeCjsModule({}).runInputCmd('*R').then(resp => {
59
resp.o;
610
});

0 commit comments

Comments
 (0)