Skip to content

Commit

Permalink
Properly deal with empty lines
Browse files Browse the repository at this point in the history
Skip empty lines as they produce errors.
While inserting add an extra \n so that a new isn't simply added to the end of the last link.
  • Loading branch information
skeletonkey committed Oct 24, 2022
1 parent 76642fc commit 1d6f354
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion LinkOpener.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sub get_links {
open(my $fh, '<', $link_data) || die("Unable to open file ($link_data) for read: $!\n");
while (my $line = <$fh>) {
chomp($line);
next unless $line; # don't process blank lines
my ($link, $alias, $count) = split(/\|/, $line);
$links{$link} = {
link => $link,
Expand All @@ -33,7 +34,8 @@ sub add_url {
my ($url, $name) = @_;
$name ||= '';
open(my $fh, '>>', $link_data) || die("Unable to open file ($link_data) for append: $!\n");
print $fh join($sep, $url, $name) . "\n";
# extra \n incase someone removed the last empty line
print $fh "\n" . join($sep, $url, $name) . "\n";
close($fh);
}

Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ perl linkopener.pl "$query" 2&gt;&amp;1</string>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>0.0.6</string>
<string>0.0.8</string>
<key>webaddress</key>
<string>https://github.com/skeletonkey/link_opener</string>
</dict>
Expand Down

0 comments on commit 1d6f354

Please sign in to comment.