forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#45086 from gsmet/sanitize-git-url
Sanitize remote URL in Info extension
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
extensions/info/deployment/src/main/java/io/quarkus/info/deployment/GitUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.info.deployment; | ||
|
||
class GitUtil { | ||
|
||
static String sanitizeRemoteUrl(String remoteUrl) { | ||
if (remoteUrl == null || remoteUrl.isBlank()) { | ||
return null; | ||
} | ||
|
||
String sanitizedRemoteUrl = remoteUrl.trim(); | ||
if (sanitizedRemoteUrl.startsWith("https://")) { | ||
int atSign = sanitizedRemoteUrl.indexOf('@'); | ||
if (atSign > 0) { | ||
sanitizedRemoteUrl = "https://" + sanitizedRemoteUrl.substring(atSign + 1); | ||
} | ||
} else if (sanitizedRemoteUrl.startsWith("http://")) { | ||
int atSign = sanitizedRemoteUrl.indexOf('@'); | ||
if (atSign > 0) { | ||
sanitizedRemoteUrl = "http://" + sanitizedRemoteUrl.substring(atSign + 1); | ||
} | ||
} else { | ||
int atSign = sanitizedRemoteUrl.indexOf('@'); | ||
if (atSign > 0) { | ||
sanitizedRemoteUrl = sanitizedRemoteUrl.substring(atSign + 1); | ||
} | ||
} | ||
|
||
return sanitizedRemoteUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
extensions/info/deployment/src/test/java/io/quarkus/info/deployment/GitUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.info.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class GitUtilTest { | ||
|
||
@Test | ||
public void testSanitizeRemoteUrl() { | ||
assertNull(GitUtil.sanitizeRemoteUrl(null)); | ||
assertNull(GitUtil.sanitizeRemoteUrl("")); | ||
assertNull(GitUtil.sanitizeRemoteUrl(" ")); | ||
assertEquals("github.com:gsmet/quarkusio.github.io.git", | ||
GitUtil.sanitizeRemoteUrl("[email protected]:gsmet/quarkusio.github.io.git")); | ||
assertEquals("github.com:gsmet/quarkusio.github.io.git", | ||
GitUtil.sanitizeRemoteUrl(" [email protected]:gsmet/quarkusio.github.io.git ")); | ||
assertEquals("https://github.com/gsmet/quarkusio.github.io.git", | ||
GitUtil.sanitizeRemoteUrl("https://github.com/gsmet/quarkusio.github.io.git")); | ||
assertEquals("https://github.com/gsmet/quarkusio.github.io.git", | ||
GitUtil.sanitizeRemoteUrl("https://gsmet:[email protected]/gsmet/quarkusio.github.io.git")); | ||
assertEquals("http://github.com/gsmet/quarkusio.github.io.git", | ||
GitUtil.sanitizeRemoteUrl("http://gsmet:[email protected]/gsmet/quarkusio.github.io.git")); | ||
} | ||
} |