X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=38770f4e3214f6d30d10c5f94e4567d38e6b6fd3;hp=3f0c34a15004a9da88806366bee51967278700d5;hb=1460bda6f80b6529e31a1a63029dc0ec5f7d0ae8;hpb=14247790278d45e98004ef54b8ba700d10f3193a diff --git a/src/lib/util.cc b/src/lib/util.cc index 3f0c34a15..38770f4e3 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -658,7 +658,7 @@ video_asset_filename (shared_ptr asset, int reel_index, int r values['r'] = raw_convert (reel_index + 1); values['n'] = raw_convert (reel_count); if (summary) { - values['c'] = summary.get(); + values['c'] = careful_string_filter (summary.get()); } return Config::instance()->dcp_asset_filename_format().get(values, "_" + asset->id() + ".mxf"); } @@ -671,7 +671,7 @@ audio_asset_filename (shared_ptr asset, int reel_index, int ree values['r'] = raw_convert (reel_index + 1); values['n'] = raw_convert (reel_count); if (summary) { - values['c'] = summary.get(); + values['c'] = careful_string_filter (summary.get()); } return Config::instance()->dcp_asset_filename_format().get(values, "_" + asset->id() + ".mxf"); } @@ -687,3 +687,22 @@ relaxed_string_to_float (string s) return lexical_cast (s); } } + +string +careful_string_filter (string s) +{ + /* Filter out `bad' characters which `may' cause problems with some systems (either for DCP name or filename). + There's no apparent list of what really is allowed, so this is a guess. + Safety first and all that. + */ + + string out; + string const allowed = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_%."; + for (size_t i = 0; i < s.size(); ++i) { + if (allowed.find (s[i]) != string::npos) { + out += s[i]; + } + } + + return out; +}