Skip to content

Commit

Permalink
[FIXED JENKINS-7496] fix quoting issue in view parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetti committed May 1, 2012
1 parent 7eab18d commit d5ba5f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/main/java/hudson/plugins/perforce/PerforceSCM.java
Expand Up @@ -1924,6 +1924,7 @@ public FormValidation doCheckProjectPath(@QueryParameter String value) throws IO
!DEPOT_ONLY_QUOTED.matcher(mapping).matches() &&
!DEPOT_AND_WORKSPACE_QUOTED.matcher(mapping).matches() &&
!DEPOT_AND_QUOTED_WORKSPACE.matcher(mapping).matches() &&
!QUOTED_DEPOT_AND_WORKSPACE.matcher(mapping).matches() &&
!COMMENT.matcher(mapping).matches())
return FormValidation.error("Invalid mapping:" + mapping);
}
Expand Down Expand Up @@ -2069,6 +2070,8 @@ public String getAppName() {
Pattern.compile("^\\s*\"([+-]?//\\S+?/[^\"]+)\"\\s+\"//\\S+?(/[^\"]+)\"$");
private static final Pattern DEPOT_AND_QUOTED_WORKSPACE =
Pattern.compile("^\\s*([+-]?//\\S+?/\\S+)\\s+\"//\\S+?(/[^\"]+)\"$");
private static final Pattern QUOTED_DEPOT_AND_WORKSPACE =
Pattern.compile("^\\s*\"([+-]?//\\S+?/[^\"]+)\"\\s+//\\S+?(/\\S+)$");

/**
* Parses the projectPath into a list of pairs of strings representing the depot and client
Expand Down Expand Up @@ -2115,9 +2118,15 @@ public static List<String> parseProjectPath(String projectPath, String p4Client,
parsed.add(depotAndQuotedWorkspace.group(1));
parsed.add("\"//" + p4Client + depotAndQuotedWorkspace.group(2) + "\"");
} else {
// Assume anything else is a comment and ignore it
// Throw a warning anyways.
log.println("Warning: Client Spec line invalid, ignoring. ("+line+")");
Matcher quotedDepotAndWorkspace = QUOTED_DEPOT_AND_WORKSPACE.matcher(line);
if (quotedDepotAndWorkspace.find()) {
parsed.add("\"" + quotedDepotAndWorkspace.group(1) + "\"");
parsed.add("//" + p4Client + quotedDepotAndWorkspace.group(2));
} else {
// Assume anything else is a comment and ignore it
// Throw a warning anyways.
log.println("Warning: Client Spec line invalid, ignoring. ("+line+")");
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/hudson/plugins/perforce/PerforceSCMTest.java
Expand Up @@ -176,6 +176,8 @@ public void testViewParsingPairs() throws Exception {
assertViewParsesSame("//depot/path/a/b/c/... //client/path/a/b/c/...");
assertViewParsesSame("\"//depot/quotedpath/...\" \"//client/quotedpath/...\"");
assertViewParsesSame("\"//depot/path with space/...\" \"//client/path with space/...\"");
assertViewParsesSame("//depot/pathwithoutspace/... \"//client/path with space/...\"");
assertViewParsesSame("\"//depot/path with space/...\" //client/pathwithoutspace/...");
assertViewParsesSame("-//depot/path/sub/... //client/path/sub/...");
}

Expand Down Expand Up @@ -257,7 +259,7 @@ public void testFileInView() throws Exception {
assertEquals(true, PerforceSCM.isFileInView("//depot/someotherfile/test", projectPath, true));
assertEquals(true,PerforceSCM.isFileInView("//depot/somefile/file", projectPath, true));
}

/** Test migration from "p4Exe" field to tool installation.
*
* @throws Exception
Expand Down Expand Up @@ -291,4 +293,5 @@ static void assertEquals(PerforceToolInstallation[] expected, PerforceToolInstal
assertTrue("Was not expecting tool installation '" + actualTool.getName() + "'.", found);
}
}

}

0 comments on commit d5ba5f9

Please sign in to comment.