提交 21ffd868 编写于 作者: J Jesse Glick

Incorrect handling of relative paths from createItem, especially from a folder.

上级 1873c6fb
......@@ -137,7 +137,7 @@ public abstract class ItemGroupMixIn {
};
/**
* Creates a {@link TopLevelItem} from the submission of the '/lib/hudson/newFromList/formList'
* Creates a {@link TopLevelItem} for example from the submission of the {@code /lib/hudson/newFromList/form} tag
* or throws an exception if it fails.
*/
public synchronized TopLevelItem createTopLevelItem( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
......@@ -170,12 +170,7 @@ public abstract class ItemGroupMixIn {
String from = req.getParameter("from");
// resolve a name to Item
Item src = null;
if (!from.startsWith("/"))
src = parent.getItem(from);
if (src==null)
src = Jenkins.getInstance().getItemByFullName(from);
Item src = Jenkins.getInstance().getItem(from, parent);
if(src==null) {
if(Util.fixEmpty(from)==null)
throw new Failure("Specify which job to copy");
......
......@@ -23,7 +23,7 @@
*/
package hudson.jobs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import java.net.URL;
import java.text.MessageFormat;
......@@ -37,6 +37,8 @@ import org.jvnet.hudson.test.JenkinsRule;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebRequest;
import hudson.model.FreeStyleProject;
import org.jvnet.hudson.test.MockFolder;
/**
* Tests the /createItem REST API.
......@@ -82,4 +84,16 @@ public class CreateItemTest {
private void deleteContentTypeHeader(WebRequest request) {
request.setEncodingType(null);
}
@Test
public void createWithFolderPaths() throws Exception {
rule.jenkins.setCrumbIssuer(null);
rule.createFolder("d1").createProject(FreeStyleProject.class, "p");
MockFolder d2 = rule.createFolder("d2");
rule.createWebClient().getPage(new WebRequest(new URL(d2.getAbsoluteUrl() + "createItem?mode=copy&name=p2&from=../d1/p"), HttpMethod.POST));
assertNotNull(d2.getItem("p2"));
rule.createWebClient().getPage(new WebRequest(new URL(d2.getAbsoluteUrl() + "createItem?mode=copy&name=p3&from=/d1/p"), HttpMethod.POST));
assertNotNull(d2.getItem("p3"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册