CMake: Fix unescaped path MATCH condition in QtPublicSbomHelpers

Use string(FIND) instead of if(MATCH) since paths containing special
regex symbols like "+", can either cause an invalid MATCH result or it
can lead to regex compilation errors like
 RegularExpression::compile(): Nested *?+.
 RegularExpression::compile(): Error in compile.

Amends 6e7f871edfd35174b40c7eb7386282bfe019f276

Fixes: QTBUG-131782
Task-number: QTBUG-122899
Task-number: QTBUG-130557
Change-Id: I59a2c3e4fe2431303c7cbca8fd54360f254da90f
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit 9cb0d48aae81c5436bda783b64721d0b77bc3f6c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2024-12-02 15:02:19 +01:00 committed by Qt Cherry-pick Bot
parent 8c0867699c
commit cdd257c674

View File

@ -1548,9 +1548,13 @@ function(_qt_internal_sbom_map_path_to_reproducible_relative_path out_var)
else()
if(IS_ABSOLUTE "${path}")
set(path_in "${path}")
if(path MATCHES "^${PROJECT_SOURCE_DIR}/")
string(FIND "${path}" "${PROJECT_SOURCE_DIR}/" src_idx)
string(FIND "${path}" "${PROJECT_BINARY_DIR}/" dest_idx)
if(src_idx EQUAL "0")
set(is_in_source_dir TRUE)
elseif(path MATCHES "^${PROJECT_BINARY_DIR}/")
elseif(dest_idx EQUAL "0")
set(is_in_build_dir TRUE)
endif()
else()