package org.jenkinsci.plugins.gitclient;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.jvnet.hudson.test.Issue;

@RunWith(Parameterized.class)
public class SubmodulePatternStringTest {

    private final String remoteName;
    private final String submoduleConfigOutput;
    private final Matcher matcher;

    private static final Pattern SUBMODULE_CONFIG_PATTERN = Pattern.compile(CliGitAPIImpl.SUBMODULE_REMOTE_PATTERN_STRING, Pattern.MULTILINE);

    public SubmodulePatternStringTest(String repoUrl, String remoteName)
    {
        this.remoteName = remoteName;
        this.submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
        this.matcher = SUBMODULE_CONFIG_PATTERN.matcher(submoduleConfigOutput);
    }

    /*
     * Permutations of repository URLs and remote names with various
     * protocols and remote names, permuted with various suffixes.
     *
     * Tests file, ssh (both forms), git, and https.
     */
    @Parameterized.Parameters(name = "{0}-{1}")
    public static Collection repoAndRemote() {
        List<Object[]> arguments = new ArrayList<>();
        String[] repoUrls = {
            "file://gitroot/thirdparty.url.repo",
            "git://gitroot/repo",
            "git@github.com:jenkinsci/JENKINS-46054",
            "https://github.com/MarkEWaite/JENKINS-46054",
            "https://mark.url:some%20pass.urlify@gitroot/repo",
            "ssh://git.example.com/MarkEWaite/JENKINS-46054",
        };
        String[] remoteNames = {
            "has space",
            "has.url space",
            "simple",
            "simple.name",
            "simple.url.name",
        };
        String [] suffixes = {
            "",
            ".git",
            ".url",
            ".url.git",
        };
        for (String repoUrlParam : repoUrls) {
            for (String repoUrlSuffix : suffixes) {
                for (String remoteNameParam : remoteNames) {
                    for (String remoteNameSuffix : suffixes) {
                        Object[] item = {repoUrlParam + repoUrlSuffix, remoteNameParam + remoteNameSuffix};
                        arguments.add(item);
                    }
                }
            }
        }
        return arguments;
    }

    @Issue("JENKINS-46054")
    @Test
    public void urlFoundInSubmoduleConfigOutput() {
        assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
        assertThat(matcher.group(1), is(remoteName));
    }
}

@@ -1741,32 +1741,282 @@
 JENKINS-46054%22,%0A
+            // JENKINS-56175 notes that submodule URL's with spaces don't%0A            // work in the git plugin. This test shows they don't work at%0A            // one level. Other levels also have failures.%0A            // %22file://gitroot/has space%22,%0A
         %7D;%0A     
@@ -2002,32 +2002,32 @@
 ce%22,%0A        %7D;%0A
-
         String%5B%5D
@@ -2169,32 +2169,90 @@
 mple.url.name%22,%0A
+            %22url%22,%0A            %22modules/module.named.url%22%0A
         %7D;%0A     
@@ -2329,24 +2329,24 @@
     %22.url%22,%0A
-
             
@@ -2353,24 +2353,48 @@
 %22.url.git%22,%0A
+            %22.git.url%22,%0A
         %7D;%0A 

Add JENKINS-56175 test case as a comment