Subject: | _load in Win32::IEFavorites::Item Fail when a .url file is corrupt or missing information |
Date: | Sat, 21 Apr 2012 22:49:16 +0800 |
To: | <bug-Win32-IEFavorites [...] rt.cpan.org> |
From: | "Shiraz Qureshi" <collectjunkemail [...] hotmail.com> |
Hi;
I came across an issue where the .url in the Favorites was a recovered .url, which was missing information like url path, etc. It was a completely empty .url file except it was present and had a valid path and name. In this case, the Item.pm would cause an error when the calling perl script would invoke $my_item->url. This call invoked the _load in the process and the error would happen where there was nothing handling for the case if my $ini = undef. If I added the check to confirm $ini is defined prior to using it then the error from Perl disappeared. The Perl error was Can't call method ‘val’ on an undefined value... I have provided the following sample code to fix the issue.
sub _load {
my $self = shift;
my $ini = Config::IniFiles->new( -file => $self->{path} );
foreach my $type (qw/URL Modified IconFile IconIndex/) {
if (defined $ini){
$self->{lc($type)} = $ini->val('InternetShortcut',$type) || '';
} else {
$self->{lc($type)} = '';
}
}
$self->{cached} = 1;
}
Thank you for writing this code in the first place.
Regards
Sam