FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

resolved issue #40 by Plamen5kov · Pull Request #1 · NativeScript/android · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .java  (1) .js  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions src/assets/app/mainpage.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require("./tests/stringConversionTests");
require("./tests/testsForTypescript");
require("./tests/testGC");
require("./tests/testsMemoryManagement");
require("./tests/testIfAbleToRunExternalFile");

var MainActivity = com.tns.NativeScriptActivity.extends({
onCreate: function() {
Expand Down
34 changes: 34 additions & 0 deletions src/assets/app/tests/testIfAbleToRunExternalFile.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var Assert = function(condition, failMessage) {
if (condition == false) {
fail(failMessage);
}
}

var When_file_outside_the_project_folder_is_required_it_should_fail = function() {

Log("When_file_outside_the_project_folder_is_required_it_should_throw_IllegalAccessException");

var illegalAccesExceptionCaught = false;
var fileSeparator = "/";
var nonExistingFileName = "nonExistingFile";
var nonExistingFileExtension = ".js";

//create a file in external storage
var pathToExternalStorage = android.os.Environment.getExternalStorageDirectory().toString();
var appDirectory = new java.io.File(pathToExternalStorage + fileSeparator + nonExistingFileName + nonExistingFileExtension);
appDirectory.mkdirs();

try
{
//try to require it with absolute path (requireing files with absolute path should not be possible)
require(pathToExternalStorage + fileSeparator + nonExistingFileName);
}
catch(e)
{
exceptionCaught = true;
}

Assert(exceptionCaught === true, "When_file_outside_the_project_folder_is_required_it_should_fail FAILED: Exception(illegal access) should be thrown");
}

When_file_outside_the_project_folder_is_required_it_should_fail();
9 changes: 9 additions & 0 deletions src/jni/NativeScriptRuntime.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,15 @@ void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo<v8::Val
ExceptionUtil::GetInstance()->HandleInvalidState(exception, false);
return;
}
if (modulePath == "EXTERNAL_FILE_ERROR")
{
// module not found
stringstream ss;
ss << "Module \"" << moduleName << "\" is located on the external storage. Modules can be private application files ONLY";
string exception = ss.str();
ExceptionUtil::GetInstance()->HandleInvalidState(exception, false);
return;
}

auto it = loadedModules.find(modulePath);

Expand Down
6 changes: 3 additions & 3 deletions src/src/com/tns/Require.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static String getModulePath(String moduleName, String callingModuleName)
File projectRootDir = new File(RootPackageDir);
if (isFileExternal(file, projectRootDir))
{
throw new IllegalAccessError();
return "EXTERNAL_FILE_ERROR";
}
else
{
Expand All @@ -128,12 +128,12 @@ private static boolean isFileExternal(File source, File target)

while (currentParentDir != null)
{
currentParentDir = currentParentDir.getParentFile();

if (currentParentDir.equals(target))
{
return false;
}

currentParentDir = currentParentDir.getParentFile();
}

return true;
Expand Down

Back | FazBrowse Home | New Git URL