From ec44118056424043a3ea8492b5cf5e1461dd41cb Mon Sep 17 00:00:00 2001
From: lfcyja <cyjada@bluewin.ch>
Date: Wed, 19 Jul 2023 17:05:25 +0200
Subject: [PATCH] fix(datasource): re-encode URL to support white spaces in
 Azure projects (#23354)

---
 .../git-submodules/__fixtures__/.gitmodules.6 |  3 +++
 .../manager/git-submodules/extract.spec.ts    | 24 +++++++++++++++++++
 lib/util/git/url.ts                           |  2 +-
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 lib/modules/manager/git-submodules/__fixtures__/.gitmodules.6

diff --git a/lib/modules/manager/git-submodules/__fixtures__/.gitmodules.6 b/lib/modules/manager/git-submodules/__fixtures__/.gitmodules.6
new file mode 100644
index 0000000000..05945a1bbc
--- /dev/null
+++ b/lib/modules/manager/git-submodules/__fixtures__/.gitmodules.6
@@ -0,0 +1,3 @@
+[submodule "some-azure"]
+  path = some-azure
+  url = https://organization@dev.azure.com/organization/whitespace%20project/_git/repo
diff --git a/lib/modules/manager/git-submodules/extract.spec.ts b/lib/modules/manager/git-submodules/extract.spec.ts
index c6e53cc5ea..a297bcceff 100644
--- a/lib/modules/manager/git-submodules/extract.spec.ts
+++ b/lib/modules/manager/git-submodules/extract.spec.ts
@@ -164,5 +164,29 @@ describe('modules/manager/git-submodules/extract', () => {
         ],
       });
     });
+
+    it('whitespaces in submodule URL are encoded properly', async () => {
+      hostRules.add({
+        matchHost: 'organization@dev.azure.com/organization',
+        token: 'pat',
+        hostType: 'azure',
+      });
+      gitMock.listRemote.mockResolvedValueOnce(
+        'ref: refs/heads/main  HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964        HEAD'
+      );
+      const res = await extractPackageFile('', '.gitmodules.6', {});
+      expect(res).toEqual({
+        datasource: 'git-refs',
+        deps: [
+          {
+            currentDigest: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
+            currentValue: 'main',
+            depName: 'some-azure',
+            packageName:
+              'https://organization@dev.azure.com/organization/whitespace%20project/_git/repo',
+          },
+        ],
+      });
+    });
   });
 });
diff --git a/lib/util/git/url.ts b/lib/util/git/url.ts
index fe3174d201..4dd08563f1 100644
--- a/lib/util/git/url.ts
+++ b/lib/util/git/url.ts
@@ -32,7 +32,7 @@ export function getHttpUrl(url: string, token?: string): string {
     }
   }
 
-  return parsedUrl.toString(protocol);
+  return new URL(parsedUrl.toString(protocol)).href;
 }
 
 export function getRemoteUrlWithToken(url: string, hostType?: string): string {
-- 
GitLab