fix(android): StringIndexOutOfBoundsException with invalid drawables (#9563)

* fix(android/application): org.nativescript.widgets.Utils::getDrawable

* chore: fix spacing

* fix(android/application): do not load empty path

Co-authored-by: Igor Randjelovic <rigor789@gmail.com>

* test: Add tests for empty image sources

* chore: add a few more test cases

These make the app crash without the fix in place

Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
Co-authored-by: Nathan Walker <walkerrunpdx@gmail.com>
This commit is contained in:
Sébastien JEAN
2021-09-25 09:54:34 +02:00
committed by GitHub
parent db7b02a418
commit 8e76bbe251
3 changed files with 41 additions and 3 deletions

View File

@@ -36,8 +36,14 @@ import java.util.concurrent.Executors;
public class Utils {
public static Drawable getDrawable(String uri, Context context){
String resPath = uri.substring("res://".length());
int resId = context.getResources().getIdentifier(resPath, "drawable", context.getPackageName());
int resId = 0;
int resPrefixLength = "res://".length();
if (uri.length() > resPrefixLength) {
String resPath = uri.substring(resPrefixLength);
resId = context.getResources().getIdentifier(resPath, "drawable", context.getPackageName());
}
if (resId > 0) {
return AppCompatResources.getDrawable(context, resId);
} else {