Fix for crash that happened if a rocket link had no space after => before path! #4

Merged
peteyboy merged 1 commits from rocket-no-space-bugfix into develop 2026-06-09 16:18:03 -04:00

View File

@@ -453,22 +453,46 @@ sub is_path_index{
return($result);
}
sub add_page_link{
my $linkline = shift;
my $base_url = shift;
my $uri_object;
#sub add_page_link{
# my $linkline = shift;
# my $base_url = shift;
# my $uri_object;
#my $link= $linkline=~ s/^=>[ ]*(.*$)/$1/r;
local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
local $URI::ABS_REMOTE_LEADING_DOTS = 1;
$uri_object=URI->new_abs($linkline=~ /^=>[ ]+([^ ]*)/,$base_url);
push(@page_links, $uri_object->as_string);
my $count = scalar @page_links; #scalar is size/count of links, but $#page_links is highest INDEX
return $linkline =~ s/(^=>.*$)/$1 [\>$count\]/r;
# local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
# local $URI::ABS_REMOTE_LEADING_DOTS = 1;
# $uri_object=URI->new_abs($linkline=~ /^=>[ ]+([^ ]*)/,$base_url);
#
# push(@page_links, $uri_object->as_string);
# my $count = scalar @page_links; #scalar is size/count of links, but $#page_links is highest INDEX
# return $linkline =~ s/(^=>.*$)/$1 [\>$count\]/r;
#}
sub add_page_link{
my $linkline = shift;
my $base_url = shift;
#my $link=~ /^=>[ ]+([^ ]*)/
my $link = $linkline;
my $uri_object;
$link=~ s/^=> ([^ ]*)/$1/;
#my $link=~ s/^=>[ ]*(.*$)/$1/r;
local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
local $URI::ABS_REMOTE_LEADING_DOTS = 1;
if (defined($link)){ #has to be something here or I think URI->new_abs has exception that crashes app
$uri_object=URI->new_abs($link,$base_url);
push(@page_links, $uri_object->as_string);
my $count = scalar @page_links; #scalar is size/count of links, but $#page_links is highest INDEX
#return $linkline =~ s/(^=>.*$)/$1 [\>$count\]/r; don't need to escape on the replace part of a substitution, I guess?
return $linkline =~ s/(^=> .*$)/$1 [>$count]/r;
}else{
return $linkline;
}
}
#=== NEX REQUESTS AND RESPONSE PROCESSING ===
sub load
{
@@ -489,9 +513,10 @@ sub load
$connect->port($port);
$ok= $connect->open($host);
$ok= $connect->print($path);
#TODO: What if it's not a text file? We need to check and have a download prompt and download if it's not text!
@lines =$connect->getlines(ErrMode=> 'return');
print $connect->eof();
#TODO:handle non-existant request? Die is not pretty to do here
#TODO:handle non-existent request? Die is not pretty to do here
die unless $connect->eof();
$connect->close();
my $widget= $texteditor;
@@ -503,8 +528,8 @@ sub load
my $is_index= is_path_index($path);
undef @page_links; #clear list
foreach $currentline (@lines){
if ($currentline =~ m/^=>/){
if ($is_index){
if ($is_index){ #only do this for index pages
if ($currentline =~ m/^=> /){ #check for valid rocket link with space
$currentline = add_page_link($currentline, $url);
}
}