Docs: note why fnmatch doesn't use escaping

This commit is contained in:
Campbell Barton
2024-09-13 14:15:41 +10:00
parent e79b901cc5
commit 1fa666495a
2 changed files with 12 additions and 2 deletions

View File

@@ -183,8 +183,13 @@ eUIListFilterResult uiListNameFilter::operator()(const PointerRNA & /*itemptr*/,
return UI_LIST_ITEM_FILTER_MATCHES;
}
/* Case-insensitive! */
if (fnmatch(filter_, name.c_str(), FNM_CASEFOLD | FNM_NOESCAPE) == 0) {
/* Use `fnmatch` for shell-style globing.
* - Case-insensitive.
* - Don't handle escape characters as "special" characters are not expected in names.
* Unlike shell input - `\` should be treated like any other character.
*/
const int fn_flag = FNM_CASEFOLD | FNM_NOESCAPE;
if (fnmatch(filter_, name.c_str(), fn_flag) == 0) {
return UI_LIST_ITEM_FILTER_MATCHES;
}
return UI_LIST_ITEM_FILTER_MISMATCHES;

View File

@@ -985,6 +985,11 @@ static bool outliner_element_visible_get(const Scene *scene,
static bool outliner_filter_has_name(TreeElement *te, const char *name, int flags)
{
/* Use `fnmatch` for shell-style globing.
* - Case-insensitive (optionally).
* - Don't handle escape characters as "special" characters are not expected in names.
* Unlike shell input - `\` should be treated like any other character.
*/
int fn_flag = FNM_NOESCAPE;
if ((flags & SO_FIND_CASE_SENSITIVE) == 0) {