Merge: tests: fix locale issue on non-Debian linux
[nit.git] / src / nitpm.nit
index 12fc960..df2aaa5 100644 (file)
@@ -262,7 +262,19 @@ class CommandUninstall
                end
 
                for name in args do
-                       var target_dir = nitpm_lib_dir / name
+
+                       var clean_nitpm_lib_dir = nitpm_lib_dir.simplify_path
+                       var target_dir = clean_nitpm_lib_dir / name
+
+                       # Check validity of the package to delete
+                       target_dir = target_dir.simplify_path
+                       var within_dir = target_dir.has_prefix(clean_nitpm_lib_dir + "/") and
+                               target_dir.length > clean_nitpm_lib_dir.length + 1
+                       var valid_name = name.length > 0 and name.chars.first.is_lower
+                       if not valid_name or not within_dir then
+                               print_error "Package name '{name}' is invalid"
+                               continue
+                       end
 
                        if not target_dir.file_exists or not target_dir.to_path.is_dir then
                                print_error "Package not found"
@@ -359,10 +371,10 @@ redef class Sys
        var opts = new OptionContext
 
        # Help option
-       var opt_help = new OptionBool("Show this help message", "--help", "-h")
+       var opt_help = new OptionBool("Show help message", "-h", "--help")
 
        # Verbose mode option
-       var opt_verbose = new OptionBool("Print more information", "--verbose", "-v")
+       var opt_verbose = new OptionBool("Print more information", "-v", "--verbose")
        private fun verbose: Bool do return opt_verbose.value
 
        # All command line actions, mapped to their short `name`