From a4f1f18cb43e311707206082e6a5343f9221a781 Mon Sep 17 00:00:00 2001 From: Sam Talonborn Date: Fri, 27 Oct 2023 10:20:29 -0700 Subject: [PATCH] Swap url_escape string shenanigans for proper Mojo route methods --- app/dexter.pl | 60 ++++++++++++++++---------------------- app/public/.assets/main.js | 2 +- 2 files changed, 26 insertions(+), 36 deletions(-) mode change 100644 => 100755 app/dexter.pl diff --git a/app/dexter.pl b/app/dexter.pl old mode 100644 new mode 100755 index af955f2..479a041 --- a/app/dexter.pl +++ b/app/dexter.pl @@ -3,7 +3,6 @@ use Module::Installed::Tiny qw(module_installed); use Mojolicious::Lite -signatures; -use Mojo::Util qw(url_unescape); use Readonly; @@ -250,7 +249,7 @@ sub user_has_permission_on_path ($user, $permission, $path) { my $permit = $rule_ref->[1]; my $permission = $PERMISSIONS{$permission}; - next if not $path->to_string =~ m/$regex/; + next if not $path->to_route =~ m/$regex/; return ( $permission & $permit ) == $permission; } @@ -287,7 +286,6 @@ sub get_sorts_hash_from_query ($query_string) { sub turn_string_into_path_using_url ($string, $url) { my $path = $url->path->clone->merge($string); $path = sanitize_path($path); - $path = unescape_path($path); $path = $path->trailing_slash(0); } @@ -315,7 +313,7 @@ sub user_save_file_to_path ($user, $file, $path) { my ( $code, $message ) = check_user_can_create_file($user, $path); return $code, $message if $code != 200; - my $path_string = $ROOT_DIRECTORY . $path->to_string; + my $path_string = $ROOT_DIRECTORY . $path->to_route; $file->move_to($path_string) or return 500, "Could not upload file '$path_string'!"; @@ -326,7 +324,7 @@ sub user_mkdir_at_path ($user, $path) { my ( $code, $message ) = check_user_can_create_file($user, $path); return $code, $message if $code != 200; - my $path_string = $ROOT_DIRECTORY . $path->to_string; + my $path_string = $ROOT_DIRECTORY . $path->to_route; mkdir($path_string) or return 500, "Directory '$path_string' could not be created!"; @@ -337,7 +335,7 @@ sub user_delete_path ($user, $path) { my ( $code, $message ) = check_user_can_delete_file($user, $path); return $code, $message if $code != 200; - my $path_string = $ROOT_DIRECTORY . $path->to_string; + my $path_string = $ROOT_DIRECTORY . $path->to_route; my $err = 0; if ( -d $path_string ) { $err = not rmtree($path_string); @@ -360,8 +358,8 @@ sub user_move_path_to_path ($user, $path, $new_path) { ( $code, $message ) = check_user_can_create_file($user, $new_path); return $code, $message if $code != 200; - my $path_string = $ROOT_DIRECTORY . $path->to_string; - my $new_path_string = $ROOT_DIRECTORY . $new_path->to_string; + my $path_string = $ROOT_DIRECTORY . $path->to_route; + my $new_path_string = $ROOT_DIRECTORY . $new_path->to_route; move($path_string, $new_path_string) or return 500, "Could not move file '$path_string' to '$new_path_string'!"; @@ -370,7 +368,7 @@ sub user_move_path_to_path ($user, $path, $new_path) { } sub get_files_at_path ($path) { - my $path_string = $path->to_string; + my $path_string = $path->to_route; my $directory_path = $ROOT_DIRECTORY . $path_string; opendir my $directory, $directory_path or return (); @@ -424,14 +422,6 @@ sub sort_symbol_for_order ($sort_order) { } } -sub unescape_path ($path) { - my $path_string = $path->to_string; - - $path_string = url_unescape($path_string); - - return Mojo::Path->new($path_string); -} - sub get_file_with_name ($name) { my ( $device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, @@ -446,21 +436,21 @@ sub get_file_with_name ($name) { } my %file = ( - name => $name, - device => $device, - inode => $inode, - mode => $mode, - nlink => $nlink, - uid => $uid, - gid => $gid, - rdev => $rdev, - size => $size, - atime => $atime, - mtime => $mtime, - ctime => $ctime, - blksize => $blksize, - blocks => $blocks, - type => $type, + name => $name, + device => $device, + inode => $inode, + mode => $mode, + nlink => $nlink, + uid => $uid, + gid => $gid, + rdev => $rdev, + size => $size, + atime => $atime, + mtime => $mtime, + ctime => $ctime, + blksize => $blksize, + blocks => $blocks, + type => $type, ); return \%file; @@ -550,7 +540,7 @@ sub parse_sort_query ($query_string) { } sub check_user_can_create_file ($user, $path) { - my $path_string = $path->to_string; + my $path_string = $path->to_route; if ( not user_has_permission_on_path($user, 'CREATE', $path) ) { return 403, "You do not have permission to create '$path_string'!"; @@ -560,7 +550,7 @@ sub check_user_can_create_file ($user, $path) { return 409, "'$path_string' already exists!"; } - my $parent = $path->to_dir->to_string; + my $parent = $path->to_dir->to_route; if ( not -e $ROOT_DIRECTORY . $parent ) { return 409, "Parent directory '$parent' does not exist!"; @@ -574,7 +564,7 @@ sub check_user_can_create_file ($user, $path) { } sub check_user_can_delete_file ($user, $path) { - my $path_string = $path->to_string; + my $path_string = $path->to_route; if ( not user_has_permission_on_path($user, 'DELETE', $path) ) { return 403, "You do not have permission to delete '$path_string'!"; diff --git a/app/public/.assets/main.js b/app/public/.assets/main.js index b7a5a92..641e90d 100644 --- a/app/public/.assets/main.js +++ b/app/public/.assets/main.js @@ -68,4 +68,4 @@ function get_file_name_from_url(url) { } return name; -} \ No newline at end of file +}