From ff91c47f68622f0efe44328eacf7afae9ff6c615 Mon Sep 17 00:00:00 2001 From: Dean Ferreyra Date: Thu, 3 Sep 2020 22:59:24 -0700 Subject: [PATCH] Fix restore GUI for filters with wildcard characters Change RestoreController.js to handle the case where the selected restore paths contain literal wildcard characters. For files, prefix with `@`. For directories, convert to regular expression filters so that we can preserve the literal wildcard characters and also support the equivalent of a globbing `*` suffix. --- .../scripts/controllers/RestoreController.js | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Duplicati/Server/webroot/ngax/scripts/controllers/RestoreController.js b/Duplicati/Server/webroot/ngax/scripts/controllers/RestoreController.js index 0ff98a378..650d414fa 100644 --- a/Duplicati/Server/webroot/ngax/scripts/controllers/RestoreController.js +++ b/Duplicati/Server/webroot/ngax/scripts/controllers/RestoreController.js @@ -346,10 +346,27 @@ backupApp.controller('RestoreController', function ($rootScope, $scope, $routePa var paths = []; for(var n in $scope.Selected) { var item = $scope.Selected[n]; - if (item.substr(item.length - 1) == dirsep) - paths.push(item + '*'); - else - paths.push(item); + if (item.indexOf('*') >= 0 || item.indexOf('?')) { + // Handle paths with literal wildcard characters + // specially + if (item.substr(item.length - 1) == dirsep) { + // Switch to a regular expression filter so we can + // preserve the literal wildcard characters and + // also support the equivalent of a globbing '*' + // suffix. + + // Escape regular expression metacharacters + var itemRegex = item.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + paths.push('[' + itemRegex + '.*]'); + } else { + paths.push('@' + item); + } + } else { + if (item.substr(item.length - 1) == dirsep) + paths.push(item + '*'); + else + paths.push(item); + } } if (paths.length > 0)