From aacbd60c806ed9767b45e95716d11dcbe21fd45c Mon Sep 17 00:00:00 2001 From: changlong-liu <59815250+changlong-liu@users.noreply.github.com> Date: Tue, 1 Sep 2020 10:49:56 +0800 Subject: [PATCH] fix issue #11658 for is_valid_resource_id (#11709) * fix issue #11658 * use regex * add tests * revert print --- sdk/core/azure-mgmt-core/azure/mgmt/core/tools.py | 8 ++++---- sdk/core/azure-mgmt-core/tests/test_tools.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/core/azure-mgmt-core/azure/mgmt/core/tools.py b/sdk/core/azure-mgmt-core/azure/mgmt/core/tools.py index 18502db70977b..ce671e5725161 100644 --- a/sdk/core/azure-mgmt-core/azure/mgmt/core/tools.py +++ b/sdk/core/azure-mgmt-core/azure/mgmt/core/tools.py @@ -30,13 +30,13 @@ _LOGGER = logging.getLogger(__name__) _ARMID_RE = re.compile( - "(?i)/subscriptions/(?P[^/]*)(/resourceGroups/(?P[^/]*))?" - "(/providers/(?P[^/]*)/(?P[^/]*)/(?P[^/]*)(?P.*))?" + "(?i)/subscriptions/(?P[^/]+)(/resourceGroups/(?P[^/]+))?" + "(/providers/(?P[^/]+)/(?P[^/]*)/(?P[^/]+)(?P.*))?" ) _CHILDREN_RE = re.compile( - "(?i)(/providers/(?P[^/]*))?/" - "(?P[^/]*)/(?P[^/]*)" + "(?i)(/providers/(?P[^/]+))?/" + "(?P[^/]*)/(?P[^/]+)" ) _ARMNAME_RE = re.compile("^[^<>%&:\\?/]{1,260}$") diff --git a/sdk/core/azure-mgmt-core/tests/test_tools.py b/sdk/core/azure-mgmt-core/tests/test_tools.py index 871b78bd754f9..831bf9b4835ce 100644 --- a/sdk/core/azure-mgmt-core/tests/test_tools.py +++ b/sdk/core/azure-mgmt-core/tests/test_tools.py @@ -239,7 +239,9 @@ def test_resource_parse(self): invalid_ids = [ '/subscriptions/fakesub/resourceGroups/myRg/type1/name1', '/subscriptions/fakesub/resourceGroups/myRg/providers/Microsoft.Provider/foo', - '/subscriptions/fakesub/resourceGroups/myRg/providers/namespace/type/name/type1' + '/subscriptions/fakesub/resourceGroups/myRg/providers/namespace/type/name/type1', + '/subscriptions/fakesub/resourceGroups/', + '/subscriptions//resourceGroups/' ] for invalid_id in invalid_ids: self.assertFalse(is_valid_resource_id(invalid_id))