Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function getIdentifier does not remove special characters #42

Closed
end2endzone opened this issue May 2, 2021 · 1 comment
Closed

Function getIdentifier does not remove special characters #42

end2endzone opened this issue May 2, 2021 · 1 comment

Comments

@end2endzone
Copy link
Owner

The function getIdentifier does not properly sanitize characters from filenames.

For example the file C:\Users\foobar\AppData\Local\Temp\demo-sample.cpp generate the identifier demo-sample which contains the invalid c++ character - (dash).

The function must remove all invalid c++ characters such as +-*/=!"/$%?&()½¾.,;<>^¸¨: .

@end2endzone
Copy link
Owner Author

end2endzone commented May 2, 2021

The solution is to change the implementation of getIdentifier() function by the following :

inline std::string filter(std::string str, const std::string & valid_characters)
{
  std::string output;
  
  //reserve as many characters as in input string
  output.reserve(str.size());

  //for each characters in input string
  for(size_t i=0; i < str.size(); i++)
  {
    //is the current character is found in valid characters?
    size_t pos = valid_characters.find(str[i], 0);
    if (pos != std::string::npos)
      output.append(1, str[i]);
  }

  return output;
}

std::string getFunctionIdentifierFromPath(const std::string & path)
{
  std::string id;

  //get filename of the given path
  id = ra::filesystem::GetFilenameWithoutExtension(path.c_str());

  // filter out characters which are not alphanumeric characters or '_'.
  static const std::string validCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
  id = filter(id, validCharacters);

  return id;
}

and to remove usage of function getIdentifier() at line 491 to generate files using the same filename as the original.

end2endzone added a commit that referenced this issue May 2, 2021
…racters.

* Moved html5skeleton sample source code under samples/demo_helloworld.
* Fixed implementation of `getCppIncludeGuardMacroName()`.
* Implemented many steps specified in issue #41.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant