Skip to content

Commit 18ad3f6

Browse files
committed
added encoded chars stripping to KVReader
1 parent fb75ef9 commit 18ad3f6

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

code/core/OS/KVReader.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ namespace OS {
4949
line_ss.read((char *)binary_data.GetHead(), data_len);
5050
line_ss.seekg(1, std::ios_base::cur);
5151
value = std::string((const char *)binary_data.GetHead(), data_len);
52-
m_kv_map.push_back(std::pair<std::string, std::string>(key, value));
52+
m_kv_map.push_back(std::pair<std::string, std::string>(cleanup_string(key), cleanup_string(value)));
5353
}
5454
else {
55-
m_kv_map.push_back(std::pair<std::string, std::string>(key, value));
55+
m_kv_map.push_back(std::pair<std::string, std::string>(cleanup_string(key), cleanup_string(value)));
5656
}
5757
}
5858
key = "";
@@ -129,17 +129,6 @@ namespace OS {
129129
}
130130
return m_kv_map.cend();
131131
}
132-
std::vector<std::pair<std::string, std::string>>::const_iterator KVReader::FindValue(std::string key) {
133-
std::vector<std::pair<std::string, std::string>>::const_iterator it = m_kv_map.cbegin();
134-
while (it != m_kv_map.cend()) {
135-
std::pair<std::string, std::string> p = *it;
136-
if (p.second.compare(key) == 0) {
137-
return it;
138-
}
139-
it++;
140-
}
141-
return m_kv_map.cend();
142-
}
143132
std::map<std::string, std::string> KVReader::GetKVMap() const {
144133
std::map<std::string, std::string> ret;
145134
std::vector<std::pair<std::string, std::string>>::const_iterator it = m_kv_map.cbegin();
@@ -168,4 +157,21 @@ namespace OS {
168157
}
169158
return ret;
170159
}
160+
/*
161+
This cleanup is due to issues handling encodings. Games will send data of *any* code page, and the json serialzier would reject those chars resulting in a crash
162+
163+
for the user input data we should base64 encode / decode instead, but for now, this will just strip those chars out
164+
*/
165+
std::string KVReader::cleanup_string(std::string input) {
166+
std::string::iterator it = input.begin();
167+
std::string result;
168+
while(it != input.end()) {
169+
char ch = *it;
170+
if(ch <= 127) {
171+
result += ch;
172+
}
173+
it++;
174+
}
175+
return result;
176+
}
171177
}

code/core/OS/KVReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace OS {
3333
int GetIndex(int n); //map internal index to external index
3434
bool IsDataKey(std::string key);
3535
std::vector<std::pair<std::string, std::string> >::const_iterator FindKey(std::string key);
36-
std::vector<std::pair<std::string, std::string> >::const_iterator FindValue(std::string key);
36+
std::string cleanup_string(std::string input);
3737
std::vector< std::pair<std::string, std::string> > m_kv_map;
3838
char m_delimitor;
3939
char m_line_delimitor;

0 commit comments

Comments
 (0)