Skip to content

Commit

Permalink
Merge pull request #1975 from Sierraffinity/jsonproc-fix
Browse files Browse the repository at this point in the history
jsonproc: filter out every non-alphanumeric character
  • Loading branch information
GriffinRichards authored Jan 28, 2024
2 parents f2276e1 + b98e044 commit 232eab4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tools/jsonproc/jsonproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ int main(int argc, char *argv[])
});

env.add_callback("cleanString", 1, [](Arguments& args) {
string badChars = ".'{} \n\t-\u00e9";
string str = args.at(0)->get<string>();
for (unsigned int i = 0; i < str.length(); i++) {
if (badChars.find(str[i]) != std::string::npos) {
// This code is not Unicode aware, so UTF-8 is not easily parsable without introducing
// another library. Just filter out any non-alphanumeric characters for now.
// TODO: proper Unicode string normalization
if ((i == 0 && isdigit(str[i]))
|| !isalnum(str[i])) {
str[i] = '_';
}
}
Expand Down

0 comments on commit 232eab4

Please sign in to comment.