2021-06-22 22:37:01 +02:00
|
|
|
# File: SafeFilename.pm
|
|
|
|
#
|
|
|
|
# Purpose: for strings containing filenames, translates potentially unsafe
|
|
|
|
# characters into safe expansions; e.g. "foo/bar" becomes "foo&fslash;bar".
|
|
|
|
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2017-09-05 04:06:31 +02:00
|
|
|
package PBot::Utils::SafeFilename;
|
2020-02-15 23:38:32 +01:00
|
|
|
|
2021-06-22 22:37:01 +02:00
|
|
|
use PBot::Imports;
|
2017-09-05 04:06:31 +02:00
|
|
|
|
|
|
|
require Exporter;
|
2020-02-15 23:38:32 +01:00
|
|
|
our @ISA = qw/Exporter/;
|
2017-09-05 04:06:31 +02:00
|
|
|
our @EXPORT = qw/safe_filename/;
|
|
|
|
|
|
|
|
sub safe_filename {
|
2021-06-22 22:37:01 +02:00
|
|
|
my ($name) = @_;
|
2020-02-15 23:38:32 +01:00
|
|
|
my $safe = '';
|
2017-09-05 04:06:31 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
while ($name =~ m/(.)/gms) {
|
|
|
|
if ($1 eq '&') { $safe .= '&'; }
|
|
|
|
elsif ($1 eq '/') { $safe .= '&fslash;'; }
|
|
|
|
else { $safe .= $1; }
|
2017-09-05 04:06:31 +02:00
|
|
|
}
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
return lc $safe;
|
2017-09-05 04:06:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|