mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 02:26:18 +00:00
Use DirectoryBrowserSupport to serve FileParameterValue
This will allow the use of Resource Root URLs for those files. Additionally, minor UI improvements: - Explicitly indicate when no file was uploaded - Do not show original file name on the UI, nobody cares
This commit is contained in:
1 parent
78aae881db
commit
bc8ea6cdb6
4 files changed
+25
-50
No files matched your search
@@ -226,46 +226,11 @@ public class FileParameterValue extends ParameterValue {
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @throws ServletException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void doDynamic(StaplerRequest request, StaplerResponse response) throws ServletException, IOException {
|
||||
if (("/" + originalFileName).equals(request.getRestOfPath())) {
|
||||
AbstractBuild build = (AbstractBuild)request.findAncestor(AbstractBuild.class).getObject();
|
||||
File fileParameter = getLocationUnderBuild(build);
|
||||
|
||||
if (!ALLOW_FOLDER_TRAVERSAL_OUTSIDE_WORKSPACE) {
|
||||
File fileParameterFolder = getFileParameterFolderUnderBuild(build);
|
||||
|
||||
//TODO can be replaced by Util#isDescendant in 2.80+
|
||||
Path child = fileParameter.getAbsoluteFile().toPath().normalize();
|
||||
Path parent = fileParameterFolder.getAbsoluteFile().toPath().normalize();
|
||||
if (!child.startsWith(parent)) {
|
||||
throw new IllegalStateException("The fileParameter tried to escape the expected folder: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
if (fileParameter.isFile()) {
|
||||
try (InputStream data = Files.newInputStream(fileParameter.toPath())) {
|
||||
long lastModified = fileParameter.lastModified();
|
||||
long contentLength = fileParameter.length();
|
||||
if (request.hasParameter("view")) {
|
||||
response.serveFile(request, data, lastModified, contentLength, "plain.txt");
|
||||
} else {
|
||||
String csp = SystemProperties.getString(DirectoryBrowserSupport.class.getName() + ".CSP", DirectoryBrowserSupport.DEFAULT_CSP_VALUE);
|
||||
if (!csp.trim().equals("")) {
|
||||
// allow users to prevent sending this header by setting empty system property
|
||||
for (String header : new String[]{"Content-Security-Policy", "X-WebKit-CSP", "X-Content-Security-Policy"}) {
|
||||
response.setHeader(header, csp);
|
||||
}
|
||||
}
|
||||
response.serveFile(request, data, lastModified, contentLength, originalFileName);
|
||||
}
|
||||
} catch (InvalidPathException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public DirectoryBrowserSupport doDynamic(StaplerRequest request, StaplerResponse response) {
|
||||
AbstractBuild build = (AbstractBuild)request.findAncestor(AbstractBuild.class).getObject();
|
||||
File fileParameter = getFileParameterFolderUnderBuild(build);
|
||||
return new DirectoryBrowserSupport(build, new FilePath(fileParameter), Messages.FileParameterValue_IndexTitle(), "folder.png", false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,16 +26,23 @@ THE SOFTWARE.
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
|
||||
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
|
||||
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
|
||||
<j:set var="escapeEntryTitleAndDescription" value="false"/>
|
||||
<f:entry title="${h.escape(it.name)}" description="${it.formattedDescription}">
|
||||
<j:if test="${it.originalFileName != null}">
|
||||
<j:invokeStatic var="encodedName" className="hudson.Util" method="rawEncode">
|
||||
<j:arg value="${it.name}" />
|
||||
</j:invokeStatic>
|
||||
<j:set var="path" value="parameter/${encodedName}/${it.originalFileName}"/>
|
||||
<a href="${path}">${it.originalFileName}</a>
|
||||
<st:nbsp/>
|
||||
<a href="${path}?view">${%view}</a>
|
||||
</j:if>
|
||||
<j:set var="escapeEntryTitleAndDescription" value="false"/>
|
||||
<f:entry title="${h.escape(it.name)}" description="${it.formattedDescription}">
|
||||
<j:choose>
|
||||
<j:when test="${it.originalFileName != null and it.originalFileName != ''}">
|
||||
<j:invokeStatic var="encodedName" className="hudson.Util" method="rawEncode">
|
||||
<j:arg value="${it.name}" />
|
||||
</j:invokeStatic>
|
||||
<j:set var="path" value="parameter/${encodedName}/${encodedName}"/>
|
||||
<a href="${path}">${%open}</a>
|
||||
<st:nbsp/>
|
||||
<a href="${path}/*view*">${%view}</a>
|
||||
</j:when>
|
||||
<j:otherwise>
|
||||
<em>
|
||||
${%nofile}
|
||||
</em>
|
||||
</j:otherwise>
|
||||
</j:choose>
|
||||
</f:entry>
|
||||
</j:jelly>
|
||||
@@ -0,0 +1 @@
|
||||
nofile=(No file was uploaded)
|
||||
@@ -412,3 +412,5 @@ ManagementLink.Category.TROUBLESHOOTING=Troubleshooting
|
||||
ManagementLink.Category.TOOLS=Tools and Actions
|
||||
ManagementLink.Category.MISC=Other
|
||||
ManagementLink.Category.UNCATEGORIZED=Uncategorized
|
||||
|
||||
FileParameterValue.IndexTitle=File Parameters
|
||||
Reference in new issue
Block a user