@@ -63,6 +63,32 @@ Settings & Settings::operator = (const Settings &other)
63
63
}
64
64
65
65
66
+ std::string Settings::sanitizeName (const std::string &name)
67
+ {
68
+ std::string n (name);
69
+
70
+ for (const char *s = " \t\n\v\f\r\b =\" {}#" ; *s; s++)
71
+ n.erase (std::remove (n.begin (), n.end (), *s), n.end ());
72
+
73
+ return n;
74
+ }
75
+
76
+
77
+ std::string Settings::sanitizeValue (const std::string &value)
78
+ {
79
+ std::string v (value);
80
+ size_t p = 0 ;
81
+
82
+ if (v.substr (0 , 3 ) == " \"\"\" " )
83
+ v.erase (0 , 3 );
84
+
85
+ while ((p = v.find (" \n\"\"\" " )) != std::string::npos)
86
+ v.erase (p, 4 );
87
+
88
+ return v;
89
+ }
90
+
91
+
66
92
std::string Settings::getMultiline (std::istream &is, size_t *num_lines)
67
93
{
68
94
size_t lines = 1 ;
@@ -683,19 +709,15 @@ void Settings::setEntry(const std::string &name, const void *data,
683
709
{
684
710
Settings *old_group = NULL ;
685
711
686
- // Strip any potentially dangerous characters from the name (note the value
687
- // has no such restrictions)
688
- std::string n (name);
689
- for (const char *s = " \t\n\v\f\r\b =\" " ; *s; s++)
690
- n.erase (std::remove (n.begin (), n.end (), *s), n.end ());
712
+ std::string n = sanitizeName (name);
691
713
692
714
{
693
715
JMutexAutoLock lock (m_mutex);
694
716
695
717
SettingsEntry &entry = set_default ? m_defaults[n] : m_settings[n];
696
718
old_group = entry.group ;
697
719
698
- entry.value = set_group ? " " : *(const std::string *)data;
720
+ entry.value = set_group ? " " : sanitizeValue ( *(const std::string *)data) ;
699
721
entry.group = set_group ? *(Settings **)data : NULL ;
700
722
entry.is_group = set_group;
701
723
}
0 commit comments