Skip to content

Commit e622434

Browse files
zhangskzcopybara-github
authored andcommitted
Escape _from_dir in install.cmake for regex special characters (e.g. c++) before REGEX REPLACE.
PiperOrigin-RevId: 605469982
1 parent f82c2ef commit e622434

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cmake/install.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ foreach(_header ${protobuf_HEADERS})
7878
elseif (_find_nosrc GREATER -1)
7979
set(_from_dir "${protobuf_SOURCE_DIR}")
8080
endif()
81+
# Escape _from_dir for regex special characters in the directory name.
82+
string(REGEX REPLACE "([.+*?\^$()[\]{}|\\])" "\\\\$1" _from_dir_regexp ${_from_dir})
8183
# On some platforms `_form_dir` ends up being just "protobuf", which can
8284
# easily match multiple times in our paths. We force it to only replace
8385
# prefixes to avoid this case.
84-
string(REGEX REPLACE "^${_from_dir}" "" _header ${_header})
86+
string(REGEX REPLACE "^${_from_dir_regexp}" "" _header ${_header})
8587
get_filename_component(_extract_from "${_from_dir}/${_header}" ABSOLUTE)
8688
get_filename_component(_extract_name ${_header} NAME)
8789
get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" DIRECTORY)

0 commit comments

Comments
 (0)