summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-02-20 00:58:31 +0000
committerCarl Hetherington <cth@carlh.net>2017-02-20 00:58:31 +0000
commit1460bda6f80b6529e31a1a63029dc0ec5f7d0ae8 (patch)
tree153f0b437ceff79e6aa305aea3bc50388109d629 /src/lib
parent14247790278d45e98004ef54b8ba700d10f3193a (diff)
Be more careful about allowing possibly-trouble-causing characters in DCP filenames.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/film.cc18
-rw-r--r--src/lib/util.cc23
-rw-r--r--src/lib/util.h1
3 files changed, 24 insertions, 18 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 2dcdf4eef..dd31388b6 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -791,24 +791,10 @@ Film::dcp_name (bool if_created_now) const
{
string unfiltered;
if (use_isdcf_name()) {
- unfiltered = isdcf_name (if_created_now);
- } else {
- unfiltered = name ();
- }
-
- /* Filter out `bad' characters which cause problems with some systems.
- There's no apparent list of what really is allowed, so this is a guess.
- */
-
- string filtered;
- string const allowed = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
- for (size_t i = 0; i < unfiltered.size(); ++i) {
- if (allowed.find (unfiltered[i]) != string::npos) {
- filtered += unfiltered[i];
- }
+ return careful_string_filter (isdcf_name (if_created_now));
}
- return filtered;
+ return careful_string_filter (name ());
}
void
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<dcp::PictureAsset> asset, int reel_index, int r
values['r'] = raw_convert<string> (reel_index + 1);
values['n'] = raw_convert<string> (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<dcp::SoundAsset> asset, int reel_index, int ree
values['r'] = raw_convert<string> (reel_index + 1);
values['n'] = raw_convert<string> (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<float> (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;
+}
diff --git a/src/lib/util.h b/src/lib/util.h
index a93ca53ac..4e6e50dd7 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -82,5 +82,6 @@ extern std::map<std::string, std::string> split_get_request (std::string url);
extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
extern float relaxed_string_to_float (std::string);
+extern std::string careful_string_filter (std::string);
#endif