name_values['s'] = i.screen->name;
name_values['i'] = i.kdm.id ();
- string const name = name_format.get(name_values, ".xml");
+ string const name = careful_string_filter(name_format.get(name_values, ".xml"));
if (zip_add (zip, name.c_str(), source) == -1) {
throw runtime_error ("failed to add KDM to ZIP archive");
}
name_values['c'] = i.screen->cinema ? i.screen->cinema->name : "";
name_values['s'] = i.screen->name;
name_values['i'] = i.kdm.id ();
- boost::filesystem::path out = directory / (name_format.get(name_values, ".xml"));
+ boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml"));
if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
i.kdm.as_xml (out);
++written;
#include <boost/range/algorithm/replace_if.hpp>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
+#include <boost/locale.hpp>
#ifdef DCPOMATIC_WINDOWS
#include <boost/locale.hpp>
#include <dbghelp.h>
#include "i18n.h"
using std::string;
+using std::wstring;
using std::setfill;
using std::ostream;
using std::endl;
Safety first and all that.
*/
+ wstring ws = boost::locale::conv::utf_to_utf<wchar_t>(s);
+
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];
+ for (size_t i = 0; i < ws.size(); ++i) {
+
+ wchar_t c = ws[i];
+
+ /* Remove some accents */
+ if (wstring(L"áàâ").find(c) != string::npos) {
+ c = 'a';
+ }
+ if (wstring(L"éèêë").find(c) != string::npos) {
+ c = 'e';
+ }
+ if (wstring(L"ö").find(c) != string::npos) {
+ c = 'o';
+ }
+ if (wstring(L"ü").find(c) != string::npos) {
+ c = 'u';
+ }
+
+ if (allowed.find(c) != string::npos) {
+ out += c;
}
}
- return out;
+ return boost::locale::conv::utf_to_utf<char>(out);
}
/** @param mapped List of mapped audio channels from a Film.
BOOST_CHECK (cc->root_to_leaf() == back->root_to_leaf());
}
#endif
+
+BOOST_AUTO_TEST_CASE (careful_string_filter_test)
+{
+ BOOST_CHECK_EQUAL ("hello_world", careful_string_filter("hello_world"));
+ BOOST_CHECK_EQUAL ("hello_world", careful_string_filter("héllo_world"));
+ BOOST_CHECK_EQUAL ("hello_world", careful_string_filter("héllo_wörld"));
+ BOOST_CHECK_EQUAL ("hello_world", careful_string_filter("héllo_wörld"));
+ BOOST_CHECK_EQUAL ("hello_world_a", careful_string_filter("héllo_wörld_à"));
+}