Filter file extensions without including the path prefix

Since the file lists contain only valid paths, it is sufficient to anchor
the regular expression at the end only instead of matching the full path.
This prevents regular expression injections.
This commit is contained in:
Steffen Olszewski 2023-05-23 19:09:32 +02:00
parent 7467f14193
commit 8cd6dd7c37

View File

@ -75,28 +75,28 @@ function(set_target_source_groups arg_TARGET)
endforeach()
set(filterSources ${sourceFiles})
list(FILTER filterSources INCLUDE REGEX "^${sourceDir}/.+\\.h(h|pp)?$")
list(FILTER filterSources INCLUDE REGEX "/.+\\.h(h|pp)?$")
source_group(
TREE "${sourceTreeDir}"
PREFIX "Header Files"
FILES ${filterSources}
)
set(filterSources ${sourceFiles})
list(FILTER filterSources INCLUDE REGEX "^${sourceDir}/.+\\.h(h|pp)?\\.in$")
list(FILTER filterSources INCLUDE REGEX "/.+\\.h(h|pp)?\\.in$")
source_group(
TREE "${sourceTreeDir}"
PREFIX "Header Templates"
FILES ${filterSources}
)
set(filterSources ${sourceFiles})
list(FILTER filterSources INCLUDE REGEX "^${sourceDir}/.+\\.c(c|xx|pp)?$")
list(FILTER filterSources INCLUDE REGEX "/.+\\.c(c|xx|pp)?$")
source_group(
TREE "${sourceTreeDir}"
PREFIX "Source Files"
FILES ${filterSources}
)
set(filterSources ${sourceFiles})
list(FILTER filterSources INCLUDE REGEX "^${sourceDir}/.+\\.c(c|xx|pp)?\\.in$")
list(FILTER filterSources INCLUDE REGEX "/.+\\.c(c|xx|pp)?\\.in$")
source_group(
TREE "${sourceTreeDir}"
PREFIX "Source Templates"
@ -104,7 +104,6 @@ function(set_target_source_groups arg_TARGET)
)
set(filterSources ${binaryFiles})
list(FILTER filterSources INCLUDE REGEX "^${binaryDir}/")
source_group(
TREE "${binaryTreeDir}"
PREFIX "Generated Files"