mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 12:32:37 +01:00
Add SafeFilename module
This commit is contained in:
parent
ba6cfdca92
commit
5e6e5cb21d
25
PBot/Utils/SafeFilename.pm
Normal file
25
PBot/Utils/SafeFilename.pm
Normal file
@ -0,0 +1,25 @@
|
||||
package PBot::Utils::SafeFilename;
|
||||
use 5.010; use warnings;
|
||||
|
||||
require Exporter;
|
||||
our @ISA = qw/Exporter/;
|
||||
our @EXPORT = qw/safe_filename/;
|
||||
|
||||
sub safe_filename {
|
||||
my $name = shift;
|
||||
my $safe = '';
|
||||
|
||||
while ($name =~ m/(.)/gms) {
|
||||
if ($1 eq '&') {
|
||||
$safe .= '&';
|
||||
} elsif ($1 eq '/') {
|
||||
$safe .= '&fslash;';
|
||||
} else {
|
||||
$safe .= $1;
|
||||
}
|
||||
}
|
||||
|
||||
return $safe;
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user