[test framework] rejecting files copied into a project from outside of a test data directory (IDEA-223901)

GitOrigin-RevId: 36efa88bb5303ac83d9356301848c3aa1b6ae1b6
This commit is contained in:
Roman Shevchenko
2019-10-02 14:35:12 +00:00
committed by intellij-monorepo-bot
parent d38eb1fe8d
commit 368eaa7581
@@ -55,7 +55,6 @@ import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
@@ -350,13 +349,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
sourceFile = candidate;
if (targetPath == sourcePath) {
Path testDataPathObj = Paths.get(testDataPath), targetPathObj = Paths.get(targetPath);
if (targetPathObj.startsWith(testDataPathObj)) {
if (targetPathObj.startsWith(testDataPathObj) && !targetPathObj.equals(testDataPathObj)) {
targetPath = testDataPathObj.relativize(targetPathObj).toString();
}
else {
targetPath = targetPathObj.getFileName().toString();
throw new IllegalArgumentException("Cannot guess target path for '" + sourcePath + "'; please specify explicitly");
}
Logger.getInstance(getClass()).warn("Absolute target path '" + sourcePath + "' trimmed to '" + targetPath + "'");
}
}
}