Selaa lähdekoodia

Add warning when (pre)loading paths with leading / (#4280 - #3106)

Fabio Alessandrelli 9 vuotta sitten
vanhempi
commit
e59820ac94
2 muutettua tiedostoa jossa 14 lisäystä ja 1 poistoa
  1. 6 1
      modules/gdscript/gd_functions.cpp
  2. 8 0
      modules/gdscript/gd_parser.cpp

+ 6 - 1
modules/gdscript/gd_functions.cpp

@@ -840,8 +840,13 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
 				r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
 				r_error.argument=0;
 				r_ret=Variant();
+			} else if(((String)(*p_args[0])).begins_with("/")) {
+				r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+				r_error.argument=0;
+				r_ret=RTR("Paths cannot start with '/', absolute paths must start with \'res://\', \'user://\', or \'local://\'");
+			} else {
+				r_ret=ResourceLoader::load(*p_args[0]);
 			}
-			r_ret=ResourceLoader::load(*p_args[0]);
 
 		} break;
 		case INST2DICT: {

+ 8 - 0
modules/gdscript/gd_parser.cpp

@@ -307,6 +307,10 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
 				_set_error("expected string constant as 'preload' argument.");
 				return NULL;
 			}
+			if (path.begins_with("/")) {
+				_set_error("Paths cannot start with '/', absolute paths must start with \'res://\', \'user://\', or \'local://\'");
+				return NULL;
+			}
 			if (!path.is_abs_path() && base_path!="")
 				path=base_path+"/"+path;
 			path = path.replace("///","//").simplify_path();
@@ -2109,6 +2113,10 @@ void GDParser::_parse_extends(ClassNode *p_class) {
 			_set_error("'extends' constant must be a string.");
 			return;
 		}
+		if (((String)(constant)).begins_with("/")) {
+			_set_error("Paths cannot start with '/', absolute paths must start with \'res://\', \'user://\', or \'local://\'");
+			return;
+		}
 
 		p_class->extends_file=constant;
 		tokenizer->advance();