]> diplodocus.org Git - flac-archive/commitdiff
Sanitize filename sanitization and quoting. I'm not sure why i was
authorepg <>
Sat, 18 Sep 2004 16:05:25 +0000 (16:05 +0000)
committerepg <>
Sat, 18 Sep 2004 16:05:25 +0000 (16:05 +0000)
s/[:'"]/_/g, momentary insanity i suppose.  All i need do is replace /
with _ on output filenames and replace ' with '\'' on filenames that
will go to the shell surrouned by '' quotes, instead of being passed
directly into a program's argv.

fa-flacd:
    (flac): Do / sanitization only, since we're not going through the
    shell, but running flac directly.

flac2mp3:
    (flac2mp3): We weren't sanitizing the input filename; start doing
    so.  Only do ' sanitization for input file and output id3tag
    information, additionally do / sanitization on $outfile.

fa-flacd
flac2mp3

index 37e79a0..822f628 100755 (executable)
--- a/fa-flacd
+++ b/fa-flacd
@@ -86,12 +86,7 @@ sub flac {
     chdir($dir) or die("chdir($dir): $!");
 
     $outfile = "$album";
-    for ($outfile) {
-        s/\//_/g;
-        s/:/_/g;
-        s/'/_/g;
-        s/"/_/g;
-    }
+    $outfile =~ s/\//_/g;
 
     verbose("Running flac\n");
     $status = system('flac', '-o', "../$artist/$outfile.flac-tmp",
index 5a92c3c..73df9b6 100755 (executable)
--- a/flac2mp3
+++ b/flac2mp3
@@ -106,15 +106,18 @@ sub flac2mp3 {
     my $track = shift;
     my $skip_arg = shift;
     my $until_arg = shift;
+    my $outfile;
 
-    my $outfile = sprintf("$artist ($album) \%02s $title.mp3", $track);
-    for ($outfile) {
-        s/\//_/g;
-        s/:/_/g;
-        s/'/_/g;
-        s/"/_/g;
+    # We'll be putting these in single quotes, so we need to escape
+    # any single quotes in the filename by closing the quote ('),
+    # putting an escaped quote (\'), and then reopening the quote (').
+    for ($fn, $title, $artist, $album, $date) {
+        s/'/'\\''/;
     }
 
+    $outfile = sprintf("$artist ($album) \%02s $title.mp3", $track);
+    $outfile =~ s/\//_/g;
+
     $until_arg ||= '';
     # XXX
     system("flac -cd $skip_arg $until_arg '$fn' | lame --preset standard --tt '$title' --ta '$artist' --tl '$album' --ty '$date' --tn $track - '$outfile'");