Skip to content

Commit fcac34d

Browse files
committed
protect include fine names from using dots from package name
1 parent f4342ae commit fcac34d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/attributes.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ namespace attributes {
633633
// if it wasn't (throws exception on io error)
634634
bool commit(const std::string& preamble = std::string());
635635

636+
// Convert a dot in package name to underscore for use in header file name
637+
std::string dotNameHelper(const std::string & name) const;
638+
636639
private:
637640

638641
// Private virtual for doWriteFunctions so the base class
@@ -717,7 +720,7 @@ namespace attributes {
717720
std::string includeDir_;
718721
};
719722

720-
// Class which manages generating PackageName_RcppExports.h header file
723+
// Class which manages generating PackageName.h header file
721724
class CppPackageIncludeGenerator : public ExportsGenerator {
722725
public:
723726
CppPackageIncludeGenerator(const std::string& packageDir,
@@ -1894,6 +1897,13 @@ namespace attributes {
18941897
return removeFile(targetFile_);
18951898
}
18961899

1900+
// Convert a possible dot in package name to underscore as needed for header file
1901+
std::string ExportsGenerator::dotNameHelper(const std::string & name) const {
1902+
std::string newname(name);
1903+
std::replace(newname.begin(), newname.end(), '.', '_');
1904+
return newname;
1905+
}
1906+
18971907
CppExportsGenerator::CppExportsGenerator(const std::string& packageDir,
18981908
const std::string& package,
18991909
const std::string& fileSep)
@@ -2128,7 +2138,7 @@ namespace attributes {
21282138
const std::string& fileSep)
21292139
: ExportsGenerator(
21302140
packageDir + fileSep + "inst" + fileSep + "include" +
2131-
fileSep + package + kRcppExportsSuffix,
2141+
fileSep + dotNameHelper(package) + kRcppExportsSuffix,
21322142
package,
21332143
"//")
21342144
{
@@ -2346,7 +2356,7 @@ namespace attributes {
23462356
const std::string& fileSep)
23472357
: ExportsGenerator(
23482358
packageDir + fileSep + "inst" + fileSep + "include" +
2349-
fileSep + package + ".h",
2359+
fileSep + dotNameHelper(package) + ".h",
23502360
package,
23512361
"//")
23522362
{
@@ -2359,7 +2369,6 @@ namespace attributes {
23592369
std::string guard = getHeaderGuard(); // #nocov start
23602370
ostr() << "#ifndef " << guard << std::endl;
23612371
ostr() << "#define " << guard << std::endl << std::endl;
2362-
23632372
ostr() << "#include \"" << packageCpp() << kRcppExportsSuffix
23642373
<< "\"" << std::endl;
23652374

0 commit comments

Comments
 (0)