diff -Nru libcommons-fileupload-java-1.3.3/build-gump.xml libcommons-fileupload-java-1.4/build-gump.xml --- libcommons-fileupload-java-1.3.3/build-gump.xml 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/build-gump.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff -Nru libcommons-fileupload-java-1.3.3/build.properties libcommons-fileupload-java-1.4/build.properties --- libcommons-fileupload-java-1.3.3/build.properties 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/build.properties 1970-01-01 00:00:00.000000000 +0000 @@ -1,93 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#Generated by Maven Ant Plugin - DO NOT EDIT THIS FILE! -#Fri Mar 08 12:53:27 CET 2013 -commons.compiler.compilerVersion= -maven.compile.source=1.5 -commons.release.2.name=commons-fileupload-${commons.release.2.version} -commons.release.desc= -maven.build.srcDir.0=src/main/java -commons.binary.suffix=-bin -commons.manifestfile=${maven.build.outputDir}/osgi/MANIFEST.MF -maven.build.timestamp.format=yyyy-MM-dd HH\:mm\:ssZ -commons.project-info.version=2.6 -maven.build.resourceDir.1=. -maven.build.resourceDir.0=src/main/resources -project.build.sourceEncoding=iso-8859-1 -sourceReleaseAssemblyDescriptor=source-release -commons.release.3.name=commons-fileupload-${commons.release.3.version} -maven.build.outputDir=${maven.build.dir}/classes -commons.componentid=fileupload -commons.site.path=commons-fileupload -maven.repo.local=${user.home}/.m2/repository -maven.build.finalName=commons-fileupload-1.3-SNAPSHOT -commons.osgi.private= -maven.build.testDir.0=src/test/java -commons.javadoc.javaee.link=http\://download.oracle.com/javaee/6/api/ -commons.osgi.export=org.apache.commons.*;version\=1.3-SNAPSHOT;-noimport\:\=true -commons.release.2.binary.suffix=-bin -maven.reporting.outputDirectory=${maven.build.dir}/site -commons.compiler.javac= -commons.encoding=iso-8859-1 -organization.logo=http\://www.apache.org/images/asf_logo_wide.gif -commons.scmPubUrl=https\://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-fileupload -sonar.host.url=https\://analysis.apache.org/ -commons.rc.version=RC1 -commons.cobertura.version=2.5.2 -commons.release.name=commons-fileupload-1.3 -minSeverity=info -maven.build.testOutputDir=${maven.build.dir}/test-classes -project.reporting.outputEncoding=iso-8859-1 -maven.build.dir=target -maven.test.reports=${maven.build.dir}/test-reports -gpg.useagent=true -commons.javadoc.version=2.9 -commons.surefire.version=2.13 -commons.changes.version=2.8 -commons.release.version=1.3 -commons.jxr.version=2.3 -commons.surefire-report.version=2.13 -commons.rat.version=0.8 -commons.site.cache=/Users/stripodi/commons-sites -project.build.outputDirectory=${maven.build.outputDir} -commons.docEncoding=iso-8859-1 -commons.javadoc.java.link=http\://download.oracle.com/javase/6/docs/api/ -commons.deployment.protocol=scp -maven.settings.offline=false -distMgmtSnapshotsName=Apache Development Snapshot Repository -maven.settings.interactiveMode=true -maven.compile.target=1.5 -commons.release.2.desc= -commons.jira.pid=12310476 -project.build.directory=${maven.build.dir} -arguments= -commons.surefire-report.aggregate=false -commons.release.3.binary.suffix=-bin -commons.wagon-ssh.version=2.3 -distMgmtSnapshotsUrl=https\://repository.apache.org/content/repositories/snapshots -maven.build.testResourceDir.1=. -maven.build.testResourceDir.0=src/test/resources -commons.osgi.dynamicImport=javax.portlet -commons.compiler.fork=false -commons.jdepend.version=2.0-beta-2 -commons.release.3.desc= -implementation.build=${scmBranch}@r${buildNumber}; 2013-03-08 12\:53\:21+0100 -commons.site-plugin.version=3.2 -commons.osgi.symbolicName=org.apache.commons.fileupload -commons.surefire.java= -commons.osgi.import=\!javax.portlet,* -commons.jira.id=FILEUPLOAD -commons.clirr.version=2.5 diff -Nru libcommons-fileupload-java-1.3.3/build.xml libcommons-fileupload-java-1.4/build.xml --- libcommons-fileupload-java-1.3.3/build.xml 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/build.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,332 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =================================== WARNING =================================== - JUnit is not present in your $ANT_HOME/lib directory. Tests not executed. - =============================================================================== - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru libcommons-fileupload-java-1.3.3/CONTRIBUTING.md libcommons-fileupload-java-1.4/CONTRIBUTING.md --- libcommons-fileupload-java-1.3.3/CONTRIBUTING.md 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/CONTRIBUTING.md 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,97 @@ + + +Contributing to Apache Commons FileUpload +====================== + +You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to +the open source community. Before you dig right into the code there are a few guidelines that we need contributors to +follow so that we can have a chance of keeping on top of things. + +Getting Started +--------------- + ++ Make sure you have a [JIRA account](https://issues.apache.org/jira/). ++ Make sure you have a [GitHub account](https://github.com/signup/free). ++ If you're planning to implement a new feature it makes sense to discuss you're changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons FileUpload's scope. ++ Submit a ticket for your issue, assuming one does not already exist. + + Clearly describe the issue including steps to reproduce when it is a bug. + + Make sure you fill in the earliest version that you know has the issue. ++ Fork the repository on GitHub. + +Making Changes +-------------- + ++ Create a topic branch from where you want to base your work (this is usually the master/trunk branch). ++ Make commits of logical units. ++ Respect the original code style: + + Only use spaces for indentation. + + Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. + + Check for unnecessary whitespace with git diff --check before committing. ++ Make sure your commit messages are in the proper format. Your commit message should contain the key of the JIRA issue. ++ Make sure you have added the necessary tests for your changes. ++ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken. + +Making Trivial Changes +---------------------- + +For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA. +In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number. + +Submitting Changes +------------------ + ++ Sign the [Contributor License Agreement][cla] if you haven't already. ++ Push your changes to a topic branch in your fork of the repository. ++ Submit a pull request to the repository in the apache organization. ++ Update your JIRA ticket and include a link to the pull request in the ticket. + +Additional Resources +-------------------- + ++ [Contributing patches](https://commons.apache.org/patches.html) ++ [Apache Commons FileUpload JIRA project page](https://issues.apache.org/jira/browse/FILEUPLOAD) ++ [Contributor License Agreement][cla] ++ [General GitHub documentation](https://help.github.com/) ++ [GitHub pull request documentation](https://help.github.com/send-pull-requests/) ++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) ++ #apachecommons IRC channel on freenode.org + +[cla]:https://www.apache.org/licenses/#clas diff -Nru libcommons-fileupload-java-1.3.3/debian/changelog libcommons-fileupload-java-1.4/debian/changelog --- libcommons-fileupload-java-1.3.3/debian/changelog 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/changelog 2020-01-27 12:19:30.000000000 +0000 @@ -1,3 +1,16 @@ +libcommons-fileupload-java (1.4-1) unstable; urgency=medium + + * New upstream release + - Refreshed the patch + - Fixed the compatibility with the Portlet API 2.0 + * Removed Damien Raude-Morvan from the uploaders (Closes: #889439) + * Standards-Version updated to 4.5.0 + * Switch to debhelper level 11 + * Use salsa.debian.org Vcs-* URLs + * Use a secure watch URL + + -- Emmanuel Bourg Mon, 27 Jan 2020 13:19:30 +0100 + libcommons-fileupload-java (1.3.3-1) unstable; urgency=medium * Team upload. diff -Nru libcommons-fileupload-java-1.3.3/debian/compat libcommons-fileupload-java-1.4/debian/compat --- libcommons-fileupload-java-1.3.3/debian/compat 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/compat 2020-01-27 11:45:38.000000000 +0000 @@ -1 +1 @@ -10 +11 diff -Nru libcommons-fileupload-java-1.3.3/debian/control libcommons-fileupload-java-1.4/debian/control --- libcommons-fileupload-java-1.3.3/debian/control 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/control 2020-01-27 11:45:38.000000000 +0000 @@ -2,11 +2,9 @@ Section: java Priority: optional Maintainer: Debian Java Maintainers -Uploaders: - Damien Raude-Morvan , - Emmanuel Bourg +Uploaders: Emmanuel Bourg Build-Depends: - debhelper (>= 10), + debhelper (>= 11), default-jdk, junit4, libcommons-io-java, @@ -14,9 +12,9 @@ libportlet-api-2.0-spec-java, libservlet3.1-java, maven-debian-helper (>= 2.0) -Standards-Version: 4.0.0 -Vcs-Git: https://anonscm.debian.org/git/pkg-java/libcommons-fileupload-java.git -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/libcommons-fileupload-java.git +Standards-Version: 4.5.0 +Vcs-Git: https://salsa.debian.org/java-team/libcommons-fileupload-java.git +Vcs-Browser: https://salsa.debian.org/java-team/libcommons-fileupload-java Homepage: http://commons.apache.org/fileupload/ Package: libcommons-fileupload-java diff -Nru libcommons-fileupload-java-1.3.3/debian/copyright libcommons-fileupload-java-1.4/debian/copyright --- libcommons-fileupload-java-1.3.3/debian/copyright 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/copyright 2020-01-27 11:45:38.000000000 +0000 @@ -4,6 +4,7 @@ Source: http://www.apache.org/dist/commons/fileupload/ Files-Excluded: .idea *.iml + site-content/* Files: * Copyright: 2002-2013, The Apache Software Foundation. diff -Nru libcommons-fileupload-java-1.3.3/debian/maven.ignoreRules libcommons-fileupload-java-1.4/debian/maven.ignoreRules --- libcommons-fileupload-java-1.3.3/debian/maven.ignoreRules 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/maven.ignoreRules 2020-01-27 11:51:59.000000000 +0000 @@ -1,8 +1,10 @@ +com.github.siom79.japicmp japicmp-maven-plugin * * * junit junit maven-plugin * * * org.apache.maven.plugins maven-assembly-plugin maven-plugin * * * org.apache.maven.plugins maven-changes-plugin maven-plugin * * * org.apache.maven.plugins maven-checkstyle-plugin maven-plugin * * * org.apache.maven.plugins maven-pmd-plugin maven-plugin * * * org.apache.maven.plugins maven-release-plugin maven-plugin * * * +org.apache.rat apache-rat-plugin * * * org.codehaus.mojo clirr-maven-plugin * * * diff -Nru libcommons-fileupload-java-1.3.3/debian/patches/001_update-tests-for-servlet3-api.patch libcommons-fileupload-java-1.4/debian/patches/001_update-tests-for-servlet3-api.patch --- libcommons-fileupload-java-1.3.3/debian/patches/001_update-tests-for-servlet3-api.patch 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/patches/001_update-tests-for-servlet3-api.patch 2020-01-27 11:46:20.000000000 +0000 @@ -26,9 +26,9 @@ import javax.servlet.http.HttpSession; +import javax.servlet.http.Part; - /** - * @version $Id$ -@@ -221,6 +230,10 @@ + public class MockHttpServletRequest implements HttpServletRequest { + +@@ -239,6 +248,10 @@ return null; } @@ -39,7 +39,7 @@ /** * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid() */ -@@ -296,6 +309,10 @@ +@@ -323,6 +336,10 @@ return iLength; } @@ -50,7 +50,7 @@ /** * For testing attack scenarios in SizesTest. */ -@@ -485,6 +502,56 @@ +@@ -536,6 +553,56 @@ return null; } @@ -107,7 +107,7 @@ private static class MyServletInputStream extends javax.servlet.ServletInputStream { -@@ -513,6 +580,17 @@ +@@ -564,6 +631,17 @@ return in.read(b, off, len); } diff -Nru libcommons-fileupload-java-1.3.3/debian/patches/002_portlet-api-compatibility.patch libcommons-fileupload-java-1.4/debian/patches/002_portlet-api-compatibility.patch --- libcommons-fileupload-java-1.3.3/debian/patches/002_portlet-api-compatibility.patch 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/patches/002_portlet-api-compatibility.patch 2020-01-27 12:18:09.000000000 +0000 @@ -0,0 +1,34 @@ +Description: Fixes the compatibility with the Portlet API 2.0 +Author: Emmanuel Bourg +Forwarded: no +--- a/src/test/java/org/apache/commons/fileupload/portlet/MockPortletActionRequest.java ++++ b/src/test/java/org/apache/commons/fileupload/portlet/MockPortletActionRequest.java +@@ -268,4 +268,28 @@ + this.characterEncoding = characterEncoding; + } + ++ @Override ++ public String getMethod() { ++ return "GET"; ++ } ++ ++ @Override ++ public javax.servlet.http.Cookie[] getCookies() { ++ return null; ++ } ++ ++ @Override ++ public Map getPublicParameterMap() { ++ return null; ++ } ++ ++ @Override ++ public Map getPrivateParameterMap() { ++ return null; ++ } ++ ++ @Override ++ public String getWindowID() { ++ return null; ++ } + } diff -Nru libcommons-fileupload-java-1.3.3/debian/patches/series libcommons-fileupload-java-1.4/debian/patches/series --- libcommons-fileupload-java-1.3.3/debian/patches/series 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/patches/series 2020-01-27 11:57:41.000000000 +0000 @@ -1 +1,2 @@ 001_update-tests-for-servlet3-api.patch +002_portlet-api-compatibility.patch diff -Nru libcommons-fileupload-java-1.3.3/debian/rules libcommons-fileupload-java-1.4/debian/rules --- libcommons-fileupload-java-1.3.3/debian/rules 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/rules 2020-01-27 11:45:57.000000000 +0000 @@ -1,10 +1,7 @@ #!/usr/bin/make -f %: - dh $@ --buildsystem=maven + dh $@ override_dh_installchangelogs: dh_installchangelogs -- RELEASE-NOTES.txt - -get-orig-source: - uscan --download-current-version --force-download --rename --repack --compression xz diff -Nru libcommons-fileupload-java-1.3.3/debian/watch libcommons-fileupload-java-1.4/debian/watch --- libcommons-fileupload-java-1.3.3/debian/watch 2017-06-23 08:33:52.000000000 +0000 +++ libcommons-fileupload-java-1.4/debian/watch 2020-01-27 11:45:38.000000000 +0000 @@ -1,2 +1,2 @@ version=3 -http://archive.apache.org/dist/commons/fileupload/source/commons-fileupload-([\.\d]+)-src.tar.gz debian uupdate +https://archive.apache.org/dist/commons/fileupload/source/commons-fileupload-([\.\d]+)-src.tar.gz diff -Nru libcommons-fileupload-java-1.3.3/gump.xml libcommons-fileupload-java-1.4/gump.xml --- libcommons-fileupload-java-1.3.3/gump.xml 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/gump.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,53 +0,0 @@ - - - - - File upload component. - - - - - - - - - - - - - - - org.apache.commons.fileupload - - - - - - - - - - - - - - - - - diff -Nru libcommons-fileupload-java-1.3.3/NOTICE.txt libcommons-fileupload-java-1.4/NOTICE.txt --- libcommons-fileupload-java-1.3.3/NOTICE.txt 2017-06-09 22:23:06.000000000 +0000 +++ libcommons-fileupload-java-1.4/NOTICE.txt 2018-12-24 07:06:01.000000000 +0000 @@ -1,5 +1,5 @@ Apache Commons FileUpload -Copyright 2002-2017 The Apache Software Foundation +Copyright 2002-2018 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). diff -Nru libcommons-fileupload-java-1.3.3/pom.xml libcommons-fileupload-java-1.4/pom.xml --- libcommons-fileupload-java-1.3.3/pom.xml 2017-06-09 22:24:28.000000000 +0000 +++ libcommons-fileupload-java-1.4/pom.xml 2018-12-24 07:06:01.000000000 +0000 @@ -21,12 +21,12 @@ org.apache.commons commons-parent - 41 + 47 commons-fileupload commons-fileupload - 1.3.3 + 1.4 Apache Commons FileUpload @@ -101,7 +101,6 @@ Rob Tompkins chtompki chtompki@apache.org - @@ -155,6 +154,10 @@ mailsurfie@gmail.com + maxxedev + maxxedev@gmail.com + + Rafal Krzewski Rafal.Krzewski@e-point.pl @@ -170,32 +173,55 @@ David Sean Taylor taylor@apache.org + + fangwentong + fangwentong2012@gmail.com + scm:git:http://git-wip-us.apache.org/repos/asf/commons-fileupload.git scm:git:https://git-wip-us.apache.org/repos/asf/commons-fileupload.git https://git-wip-us.apache.org/repos/asf?p=commons-fileupload.git - commons-fileupload-1.3.3-RC6 jira http://issues.apache.org/jira/browse/FILEUPLOAD + + + apache.website + Apache Commons Site + scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-fileupload/ + + + - 1.5 - 1.5 - ISO-8859-1 + 1.6 + 1.6 fileupload - 1.3.3 - RC1 + org.apache.commons.fileupload + (requires Java ${maven.compiler.target} or later) FILEUPLOAD 12310476 + fileupload + https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-fileupload + site-content !org.apache.commons.fileupload.util.mime,org.apache.commons.*;version=${project.version};-noimport:=true !javax.portlet,* javax.portlet - git-wip-us.apache.org + 0.13.0 + true + + + 1.4 + 1.3.3 + RC2 + true + scm:svn:https://dist.apache.org/repos/dist/dev/commons/${commons.componentid} + Rob Tompkins + B6E73D84EA4FCC47166087253FAAD2CD5ECBB314 @@ -245,44 +271,64 @@ - - - org.apache.maven.plugins - maven-release-plugin - - https://svn.apache.org/repos/asf/commons/proper/fileupload/tags - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-antrun-plugin - - [1.7,) - - run - - - - - - - - - - - + + + org.apache.rat + apache-rat-plugin + + + site-content/** + src/site/resources/download_lang.cgi + src/checkstyle/license-header.txt + + + + + com.github.siom79.japicmp + japicmp-maven-plugin + + true + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-antrun-plugin + [1.8,) + + run + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + [1.10,) + + parse-version + + + + + + + + + + + @@ -312,6 +358,7 @@ ${basedir}/src/checkstyle/fileupload_checks.xml ${basedir}/src/checkstyle/checkstyle-suppressions.xml false + ${basedir}/src/checkstyle/license-header.txt @@ -330,9 +377,71 @@ clirr-maven-plugin ${commons.clirr.version} - 1.3 + + + commons-fileupload + commons-fileupload + 1.3 + + + + + + setup-checkout + + + site-content + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + prepare-checkout + pre-site + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + java9 + + 9 + + + + true + + + diff -Nru libcommons-fileupload-java-1.3.3/README.md libcommons-fileupload-java-1.4/README.md --- libcommons-fileupload-java-1.3.3/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/README.md 2018-12-24 07:06:01.000000000 +0000 @@ -0,0 +1,104 @@ + + +Apache Commons FileUpload +=================== + +[![Build Status](https://travis-ci.org/apache/commons-fileupload.svg?branch=master)](https://travis-ci.org/apache/commons-fileupload) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/commons-fileupload/commons-fileupload/badge.svg)](https://maven-badges.herokuapp.com/maven-central/commons-fileupload/commons-fileupload/) + +The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart + file upload functionality to servlets and web applications. + +Documentation +------------- + +More information can be found on the [Apache Commons FileUpload homepage](https://commons.apache.org/proper/commons-fileupload). +The [Javadoc](https://commons.apache.org/proper/commons-fileupload/javadocs/api-release) can be browsed. +Questions related to the usage of Apache Commons FileUpload should be posted to the [user mailing list][ml]. + +Where can I get the latest release? +----------------------------------- +You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi). + +Alternatively you can pull it from the central Maven repositories: + +```xml + + commons-fileupload + commons-fileupload + 1.4 + +``` + +Contributing +------------ + +We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. +There are some guidelines which will make applying PRs easier for us: ++ No tabs! Please use spaces for indentation. ++ Respect the code style. ++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. ++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```. + +If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). +You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). + +License +------- +This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0). + +See the `NOTICE.txt` file for required notices and attributions. + +Donations +--------- +You like Apache Commons FileUpload? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. + +Additional Resources +-------------------- + ++ [Apache Commons Homepage](https://commons.apache.org/) ++ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/FILEUPLOAD) ++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) ++ `#apache-commons` IRC channel on `irc.freenode.org` + +[ml]:https://commons.apache.org/mail-lists.html diff -Nru libcommons-fileupload-java-1.3.3/RELEASE-NOTES.txt libcommons-fileupload-java-1.4/RELEASE-NOTES.txt --- libcommons-fileupload-java-1.3.3/RELEASE-NOTES.txt 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/RELEASE-NOTES.txt 2018-12-24 07:06:01.000000000 +0000 @@ -1,3 +1,48 @@ + Apache Commons FileUpload 1.4 RELEASE NOTES + +The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 1.4. + +The Apache Commons FileUpload component provides a simple yet flexible means of +adding support for multipart file upload functionality to servlets and web +applications. Version 1.3 onwards requires Java 6 or later. + +No client code changes are required to migrate from version 1.3.0 to 1.3.1. + + +1.4 Release + +Changes in version 1.4 include: + +New features: +o Site: added security report + +Fixed Bugs: +o FILEUPLOAD-252: DiskFileItem#write() could lose original IO exception +o FILEUPLOAD-258: DiskFileItem#getStoreLocation() wrongly returned a File object for items stored in memory +o FILEUPLOAD-242: FileUploadBase - should not silently catch and ignore all Throwables +o FILEUPLOAD-257: Fix Javadoc 1.8.0 errors +o FILEUPLOAD-234: Fix section "Resource cleanup" of the user guide +o FILEUPLOAD-237: Fix streaming example: use FileItem.getInputStream() instead of openStream() +o FILEUPLOAD-248: DiskFileItem might suppress critical IOExceptions on rename - use FileUtil.move instead +o FILEUPLOAD-251: DiskFileItem#getTempFile() is broken +o FILEUPLOAD-250: FileUploadBase - potential resource leak - InputStream not closed on exception +o FILEUPLOAD-244: DiskFileItem.readObject fails to close FileInputStream +o FILEUPLOAD-245: DiskFileItem.get() may not fully read the data + +Changes: +o FILEUPLOAD-292: Don't create un-needed resources in FileUploadBase.java +o FILEUPLOAD-282: Upversion complier.source, compiler.target to 1.6 +o FILEUPLOAD-246: FileUpload should use IOUtils.closeQuietly where relevant +o FILEUPLOAD-243: Make some MultipartStream private fields final Thanks to Ville Skyttä. + + +For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, +patches, or suggestions for improvement, see the Apache Apache Commons FileUpload website: + +http://commons.apache.org/proper/commons-fileupload/ + +------------------------------------------------------------------------------ + Apache Commons FileUpload 1.3.3 RELEASE NOTES The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 1.3.3. @@ -14,6 +59,20 @@ For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, +patches, or suggestions for improvement, see the Apache Apache Commons FileUpload website: + +http://commons.apache.org/proper/commons-fileupload/ + +------------------------------------------------------------------------------ + +No client code changes are required to migrate from version 1.3.1 to 1.3.2. + +Changes in version 1.3.2 include: + +o FILEUPLOAD-272: Performance Improvement in MultipartStream. Prevents a DoS (CVE-2016-3092) + + +For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Apache Commons FileUpload website: http://commons.apache.org/proper/commons-fileupload/ diff -Nru libcommons-fileupload-java-1.3.3/src/changes/changes.xml libcommons-fileupload-java-1.4/src/changes/changes.xml --- libcommons-fileupload-java-1.3.3/src/changes/changes.xml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/changes/changes.xml 2018-12-24 07:06:01.000000000 +0000 @@ -39,11 +39,34 @@ Release Notes - Martin Cooper + Apache Commons Developers - + + Don't create un-needed resources in FileUploadBase.java + Upversion complier.source, compiler.target to 1.6 + DiskFileItem#write() could lose original IO exception + DiskFileItem#getStoreLocation() wrongly returned a File object for items stored in memory + FileUploadBase - should not silently catch and ignore all Throwables + Fix Javadoc 1.8.0 errors + Fix section "Resource cleanup" of the user guide + Fix streaming example: use FileItem.getInputStream() instead of openStream() + DiskFileItem might suppress critical IOExceptions on rename - use FileUtil.move instead + DiskFileItem#getTempFile() is broken + FileUploadBase - potential resource leak - InputStream not closed on exception + DiskFileItem.readObject fails to close FileInputStream + FileUpload should use IOUtils.closeQuietly where relevant + DiskFileItem.get() may not fully read the data + Make some MultipartStream private fields final + Site: added security report + Improve performance for large multi-part boundaries + Added the default character set to the DiskFileItem. + Avoid using File.exists() on temporary files, if we know that the file has been created. + Added .travis.yml, to fix build issues on Github. + + + DiskDileItem can actually no longer be deserialized, unless a system property is set to true. @@ -51,10 +74,19 @@ - Performance Improvement in MultipartStream + SECURITY - CVE-2016-3092. Performance Improvement in MultipartStream. + + + SECURITY - CVE-2016-3092. Specially crafted input can trigger a DoS, if the + size of the MIME boundard is close to the size of the buffer in MultipartStream. + (Similar to CVE-2014-0050.) + + diff -Nru libcommons-fileupload-java-1.3.3/src/changes/release-notes.vm libcommons-fileupload-java-1.4/src/changes/release-notes.vm --- libcommons-fileupload-java-1.3.3/src/changes/release-notes.vm 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/changes/release-notes.vm 2018-12-24 07:06:01.000000000 +0000 @@ -20,9 +20,9 @@ The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web -applications. Version 1.3 onwards requires Java 5 or later. +applications. Version 1.3 onwards requires Java 6 or later. -No client code changes are required to migrate from version 1.3.0, 1.3.1, or 1.3.2 to 1.3.3. +No client code changes are required to migrate from version 1.3.0 to 1.3.1. ## N.B. the available variables are described here: diff -Nru libcommons-fileupload-java-1.3.3/src/checkstyle/fileupload_checks.xml libcommons-fileupload-java-1.4/src/checkstyle/fileupload_checks.xml --- libcommons-fileupload-java-1.3.3/src/checkstyle/fileupload_checks.xml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/checkstyle/fileupload_checks.xml 2018-12-24 06:43:43.000000000 +0000 @@ -74,6 +74,12 @@ + + + + + + diff -Nru libcommons-fileupload-java-1.3.3/src/checkstyle/license-header.txt libcommons-fileupload-java-1.4/src/checkstyle/license-header.txt --- libcommons-fileupload-java-1.3.3/src/checkstyle/license-header.txt 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/checkstyle/license-header.txt 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,16 @@ +/\*\s* + \*\s*Licensed to the Apache Software Foundation \(ASF\) under one or more + \*\s*contributor license agreements. See the NOTICE file distributed with + \*\s*this work for additional information regarding copyright ownership\. + \*\s*The ASF licenses this file to You under the Apache License, Version 2\.0 + \*\s*\(the "License"\); you may not use this file except in compliance with + \*\s*the License\. You may obtain a copy of the License at + \*\s* + \*\s*http://www\.apache\.org/licenses/LICENSE\-2\.0 + \*\s* + \*\s*Unless required by applicable law or agreed to in writing, software + \*\s*distributed under the License is distributed on an "AS IS" BASIS, + \*\s*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. + \*\s*See the License for the specific language governing permissions and + \*\s*limitations under the License\. + \*/\s* diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/DefaultFileItemFactory.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/DefaultFileItemFactory.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/DefaultFileItemFactory.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/DefaultFileItemFactory.java 2018-12-24 06:43:43.000000000 +0000 @@ -28,7 +28,7 @@ * disk, is configurable, as is the directory in which temporary files will be * created.

* - * If not otherwise configured, the default configuration values are as + *

If not otherwise configured, the default configuration values are as * follows: *

    *
  • Size threshold is 10KB.
  • @@ -36,8 +36,6 @@ * System.getProperty("java.io.tmpdir"). *
* - * @version $Id$ - * * @deprecated 1.1 Use DiskFileItemFactory instead. */ @Deprecated diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/DefaultFileItem.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/DefaultFileItem.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/DefaultFileItem.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/DefaultFileItem.java 2018-12-24 06:43:43.000000000 +0000 @@ -32,8 +32,6 @@ * {@link #getInputStream()} and process the file without attempting to load * it into memory, which may come handy with large files. * - * @version $Id$ - * * @deprecated 1.1 Use DiskFileItem instead. */ @Deprecated @@ -43,11 +41,6 @@ // ----------------------------------------------------------- Constructors /** - * The UID to use when serializing this instance. - */ - private static final long serialVersionUID = 4088572813833518255L; - - /** * Constructs a new DefaultFileItem instance. * * @param fieldName The name of the form field. diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java 2018-12-24 06:43:43.000000000 +0000 @@ -66,8 +66,6 @@ * in the users guide of commons-fileupload.

* * @since FileUpload 1.1 - * - * @version $Id$ */ public class DiskFileItemFactory implements FileItemFactory { @@ -97,6 +95,12 @@ */ private FileCleaningTracker fileCleaningTracker; + /** + * Default content charset to be used when no explicit charset + * parameter is provided by the sender. + */ + private String defaultCharset = DiskFileItem.DEFAULT_CHARSET; + // ----------------------------------------------------------- Constructors /** @@ -190,10 +194,12 @@ * * @return The newly created file item. */ + @Override public FileItem createItem(String fieldName, String contentType, boolean isFormField, String fileName) { DiskFileItem result = new DiskFileItem(fieldName, contentType, isFormField, fileName, sizeThreshold, repository); + result.setDefaultCharset(defaultCharset); FileCleaningTracker tracker = getFileCleaningTracker(); if (tracker != null) { tracker.track(result.getTempFile(), result); @@ -224,4 +230,21 @@ fileCleaningTracker = pTracker; } + /** + * Returns the default charset for use when no explicit charset + * parameter is provided by the sender. + * @return the default charset + */ + public String getDefaultCharset() { + return defaultCharset; + } + + /** + * Sets the default charset for use when no explicit charset + * parameter is provided by the sender. + * @param pCharset the default charset + */ + public void setDefaultCharset(String pCharset) { + defaultCharset = pCharset; + } } diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java 2018-12-24 06:43:43.000000000 +0000 @@ -18,16 +18,12 @@ import static java.lang.String.format; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.Map; @@ -39,6 +35,7 @@ import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.ParameterParser; import org.apache.commons.fileupload.util.Streams; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.DeferredFileOutputStream; @@ -70,26 +67,13 @@ * in the users guide of commons-fileupload.

* * @since FileUpload 1.1 - * - * @version $Id$ */ public class DiskFileItem implements FileItem { - /** - * Although it implements {@link java.io.Serializable}, a DiskFileItem can actually only be deserialized, - * if this System property is true. - */ - public static final String SERIALIZABLE_PROPERTY = DiskFileItem.class.getName() + ".serializable"; - // ----------------------------------------------------- Manifest constants /** - * The UID to use when serializing this instance. - */ - private static final long serialVersionUID = 2237570099615271025L; - - /** * Default content charset to be used when no explicit charset * parameter is provided by the sender. Media subtypes of the * "text" type are defined to have a default charset value of @@ -164,14 +148,15 @@ private transient File tempFile; /** - * File to allow for serialization of the content of this item. + * The file items headers. */ - private File dfosFile; + private FileItemHeaders headers; /** - * The file items headers. + * Default content charset to be used when no explicit charset + * parameter is provided by the sender. */ - private FileItemHeaders headers; + private String defaultCharset = DEFAULT_CHARSET; // ----------------------------------------------------------- Constructors @@ -214,6 +199,7 @@ * * @throws IOException if an error occurs. */ + @Override public InputStream getInputStream() throws IOException { if (!isInMemory()) { @@ -233,6 +219,7 @@ * @return The content type passed by the agent or null if * not defined. */ + @Override public String getContentType() { return contentType; } @@ -261,6 +248,7 @@ * use the file name anyways, catch the exception and use * {@link org.apache.commons.fileupload.InvalidFileNameException#getName()}. */ + @Override public String getName() { return Streams.checkFileName(fileName); } @@ -274,6 +262,7 @@ * @return true if the file contents will be read * from memory; false otherwise. */ + @Override public boolean isInMemory() { if (cachedContent != null) { return true; @@ -286,6 +275,7 @@ * * @return The size of the file, in bytes. */ + @Override public long getSize() { if (size >= 0) { return size; @@ -303,11 +293,13 @@ * contents of the file were not yet cached in memory, they will be * loaded from the disk storage and cached. * - * @return The contents of the file as an array of bytes. + * @return The contents of the file as an array of bytes + * or {@code null} if the data cannot be read */ + @Override public byte[] get() { if (isInMemory()) { - if (cachedContent == null) { + if (cachedContent == null && dfos != null) { cachedContent = dfos.getData(); } return cachedContent; @@ -317,18 +309,12 @@ InputStream fis = null; try { - fis = new BufferedInputStream(new FileInputStream(dfos.getFile())); - fis.read(fileData); + fis = new FileInputStream(dfos.getFile()); + IOUtils.readFully(fis, fileData); } catch (IOException e) { fileData = null; } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - // ignore - } - } + IOUtils.closeQuietly(fis); } return fileData; @@ -346,6 +332,7 @@ * @throws UnsupportedEncodingException if the requested character * encoding is not available. */ + @Override public String getString(final String charset) throws UnsupportedEncodingException { return new String(get(), charset); @@ -360,11 +347,12 @@ * * @return The contents of the file, as a string. */ + @Override public String getString() { byte[] rawdata = get(); String charset = getCharSet(); if (charset == null) { - charset = DEFAULT_CHARSET; + charset = defaultCharset; } try { return new String(rawdata, charset); @@ -393,16 +381,16 @@ * * @throws Exception if an error occurs. */ + @Override public void write(File file) throws Exception { if (isInMemory()) { FileOutputStream fout = null; try { fout = new FileOutputStream(file); fout.write(get()); + fout.close(); } finally { - if (fout != null) { - fout.close(); - } + IOUtils.closeQuietly(fout); } } else { File outputFile = getStoreLocation(); @@ -414,32 +402,7 @@ * in a temporary location so move it to the * desired file. */ - if (!outputFile.renameTo(file)) { - BufferedInputStream in = null; - BufferedOutputStream out = null; - try { - in = new BufferedInputStream( - new FileInputStream(outputFile)); - out = new BufferedOutputStream( - new FileOutputStream(file)); - IOUtils.copy(in, out); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - // ignore - } - } - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // ignore - } - } - } - } + FileUtils.moveFile(outputFile, file); } else { /* * For whatever reason we cannot write the @@ -458,10 +421,11 @@ * collected, this method can be used to ensure that this is done at an * earlier time, thus preserving system resources. */ + @Override public void delete() { cachedContent = null; File outputFile = getStoreLocation(); - if (outputFile != null && outputFile.exists()) { + if (outputFile != null && !isInMemory() && outputFile.exists()) { outputFile.delete(); } } @@ -475,6 +439,7 @@ * @see #setFieldName(java.lang.String) * */ + @Override public String getFieldName() { return fieldName; } @@ -487,6 +452,7 @@ * @see #getFieldName() * */ + @Override public void setFieldName(String fieldName) { this.fieldName = fieldName; } @@ -501,6 +467,7 @@ * @see #setFormField(boolean) * */ + @Override public boolean isFormField() { return isFormField; } @@ -515,6 +482,7 @@ * @see #isFormField() * */ + @Override public void setFormField(boolean state) { isFormField = state; } @@ -524,10 +492,11 @@ * be used for storing the contents of the file. * * @return An {@link java.io.OutputStream OutputStream} that can be used - * for storing the contensts of the file. + * for storing the contents of the file. * * @throws IOException if an error occurs. */ + @Override public OutputStream getOutputStream() throws IOException { if (dfos == null) { @@ -556,6 +525,9 @@ if (dfos == null) { return null; } + if (isInMemory()) { + return null; + } return dfos.getFile(); } @@ -566,6 +538,9 @@ */ @Override protected void finalize() { + if (dfos == null || dfos.isInMemory()) { + return; + } File outputFile = dfos.getFile(); if (outputFile != null && outputFile.exists()) { @@ -578,6 +553,9 @@ * named temporary file in the configured repository path. The lifetime of * the file is tied to the lifetime of the FileItem instance; * the file will be deleted when the instance is garbage collected. + *

+ * Note: Subclasses that override this method must ensure that they return the + * same File each time. * * @return The {@link java.io.File File} to be used for temporary storage. */ @@ -599,7 +577,7 @@ /** * Returns an identifier that is unique within the class loader used to - * load this class, but does not have random-like apearance. + * load this class, but does not have random-like appearance. * * @return A String with the non-random looking instance identifier. */ @@ -628,83 +606,11 @@ Boolean.valueOf(isFormField()), getFieldName()); } - // -------------------------------------------------- Serialization methods - - /** - * Writes the state of this object during serialization. - * - * @param out The stream to which the state should be written. - * - * @throws IOException if an error occurs. - */ - private void writeObject(ObjectOutputStream out) throws IOException { - // Read the data - if (dfos.isInMemory()) { - cachedContent = get(); - } else { - cachedContent = null; - dfosFile = dfos.getFile(); - } - - // write out values - out.defaultWriteObject(); - } - - /** - * Reads the state of this object during deserialization. - * - * @param in The stream from which the state should be read. - * - * @throws IOException if an error occurs. - * @throws ClassNotFoundException if class cannot be found. - */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException { - if (!Boolean.getBoolean(SERIALIZABLE_PROPERTY)) { - throw new IllegalStateException("Property " + SERIALIZABLE_PROPERTY - + " is not true, rejecting to deserialize a DiskFileItem."); - } - // read values - in.defaultReadObject(); - - /* One expected use of serialization is to migrate HTTP sessions - * containing a DiskFileItem between JVMs. Particularly if the JVMs are - * on different machines It is possible that the repository location is - * not valid so validate it. - */ - if (repository != null) { - if (repository.isDirectory()) { - // Check path for nulls - if (repository.getPath().contains("\0")) { - throw new IOException(format( - "The repository [%s] contains a null character", - repository.getPath())); - } - } else { - throw new IOException(format( - "The repository [%s] is not a directory", - repository.getAbsolutePath())); - } - } - - OutputStream output = getOutputStream(); - if (cachedContent != null) { - output.write(cachedContent); - } else { - FileInputStream input = new FileInputStream(dfosFile); - IOUtils.copy(input, output); - dfosFile.delete(); - dfosFile = null; - } - output.close(); - - cachedContent = null; - } - /** * Returns the file item headers. * @return The file items headers. */ + @Override public FileItemHeaders getHeaders() { return headers; } @@ -713,8 +619,26 @@ * Sets the file item headers. * @param pHeaders The file items headers. */ + @Override public void setHeaders(FileItemHeaders pHeaders) { headers = pHeaders; } + /** + * Returns the default charset for use when no explicit charset + * parameter is provided by the sender. + * @return the default charset + */ + public String getDefaultCharset() { + return defaultCharset; + } + + /** + * Sets the default charset for use when no explicit charset + * parameter is provided by the sender. + * @param charset the default charset + */ + public void setDefaultCharset(String charset) { + defaultCharset = charset; + } } diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/DiskFileUpload.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/DiskFileUpload.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/DiskFileUpload.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/DiskFileUpload.java 2018-12-24 06:43:43.000000000 +0000 @@ -34,8 +34,6 @@ * depending on their size, and will be available as {@link * org.apache.commons.fileupload.FileItem}s.

* - * @version $Id$ - * * @deprecated 1.1 Use ServletFileUpload together with * DiskFileItemFactory instead. */ diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemFactory.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemFactory.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemFactory.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemFactory.java 2018-12-24 06:43:43.000000000 +0000 @@ -20,8 +20,6 @@ *

A factory interface for creating {@link FileItem} instances. Factories * can provide their own custom configuration, over and above that provided * by the default file upload implementation.

- * - * @version $Id$ */ public interface FileItemFactory { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemHeaders.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemHeaders.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemHeaders.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemHeaders.java 2018-12-24 06:43:43.000000000 +0000 @@ -24,8 +24,6 @@ * request.

* * @since 1.2.1 - * - * @version $Id$ */ public interface FileItemHeaders { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemHeadersSupport.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemHeadersSupport.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemHeadersSupport.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemHeadersSupport.java 2018-12-24 06:43:43.000000000 +0000 @@ -24,8 +24,6 @@ * * @see FileItem * @see FileItemStream - * - * @version $Id$ */ public interface FileItemHeadersSupport { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemIterator.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemIterator.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemIterator.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemIterator.java 2018-12-24 06:43:43.000000000 +0000 @@ -21,8 +21,6 @@ /** * An iterator, as returned by * {@link FileUploadBase#getItemIterator(RequestContext)}. - * - * @version $Id$ */ public interface FileItemIterator { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItem.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItem.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItem.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItem.java 2018-12-24 06:43:43.000000000 +0000 @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.Serializable; import java.io.UnsupportedEncodingException; /** @@ -43,10 +42,9 @@ * implementation of this interface to also implement * javax.activation.DataSource with minimal additional work. * - * @version $Id$ * @since 1.3 additionally implements FileItemHeadersSupport */ -public interface FileItem extends Serializable, FileItemHeadersSupport { +public interface FileItem extends FileItemHeadersSupport { // ------------------------------- Methods from javax.activation.DataSource diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemStream.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemStream.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileItemStream.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileItemStream.java 2018-12-24 06:43:43.000000000 +0000 @@ -30,8 +30,6 @@ * its associated instances of {@link FileItemStream}: By invoking * {@link java.util.Iterator#hasNext()} on the iterator, you discard all data, * which hasn't been read so far from the previous data.

- * - * @version $Id$ */ public interface FileItemStream extends FileItemHeadersSupport { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileUploadBase.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileUploadBase.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileUploadBase.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileUploadBase.java 2018-12-24 06:43:43.000000000 +0000 @@ -38,6 +38,7 @@ import org.apache.commons.fileupload.util.FileItemHeadersImpl; import org.apache.commons.fileupload.util.LimitedInputStream; import org.apache.commons.fileupload.util.Streams; +import org.apache.commons.io.IOUtils; /** *

High level API for processing file uploads.

@@ -52,8 +53,6 @@ *

How the data for individual parts is stored is determined by the factory * used to create them; a given part may be in memory, on disk, or somewhere * else.

- * - * @version $Id$ */ public abstract class FileUploadBase { @@ -365,8 +364,8 @@ for (FileItem fileItem : items) { try { fileItem.delete(); - } catch (Throwable e) { - // ignore it + } catch (Exception ignored) { + // ignored TODO perhaps add to tracker delete failure list somehow? } } } @@ -765,20 +764,23 @@ fieldName = pFieldName; contentType = pContentType; formField = pFormField; - final ItemInputStream itemStream = multi.newInputStream(); - InputStream istream = itemStream; - if (fileSizeMax != -1) { + if (fileSizeMax != -1) { // Check if limit is already exceeded if (pContentLength != -1 - && pContentLength > fileSizeMax) { + && pContentLength > fileSizeMax) { FileSizeLimitExceededException e = - new FileSizeLimitExceededException( - format("The field %s exceeds its maximum permitted size of %s bytes.", - fieldName, Long.valueOf(fileSizeMax)), - pContentLength, fileSizeMax); + new FileSizeLimitExceededException( + format("The field %s exceeds its maximum permitted size of %s bytes.", + fieldName, Long.valueOf(fileSizeMax)), + pContentLength, fileSizeMax); e.setFileName(pName); e.setFieldName(pFieldName); throw new FileUploadIOException(e); } + } + // OK to construct stream now + final ItemInputStream itemStream = multi.newInputStream(); + InputStream istream = itemStream; + if (fileSizeMax != -1) { istream = new LimitedInputStream(istream, fileSizeMax) { @Override protected void raiseError(long pSizeMax, long pCount) @@ -803,6 +805,7 @@ * * @return Content type, if known, or null. */ + @Override public String getContentType() { return contentType; } @@ -812,6 +815,7 @@ * * @return Field name. */ + @Override public String getFieldName() { return fieldName; } @@ -825,6 +829,7 @@ * use the file name anyways, catch the exception and use * InvalidFileNameException#getName(). */ + @Override public String getName() { return Streams.checkFileName(name); } @@ -835,6 +840,7 @@ * @return True, if the item is a form field, * otherwise false. */ + @Override public boolean isFormField() { return formField; } @@ -846,6 +852,7 @@ * @return Opened input stream. * @throws IOException An I/O error occurred. */ + @Override public InputStream openStream() throws IOException { if (opened) { throw new IllegalStateException( @@ -871,6 +878,7 @@ * * @return The items header object */ + @Override public FileItemHeaders getHeaders() { return headers; } @@ -880,6 +888,7 @@ * * @param pHeaders The items header object */ + @Override public void setHeaders(FileItemHeaders pHeaders) { headers = pHeaders; } @@ -949,7 +958,6 @@ MULTIPART_FORM_DATA, MULTIPART_MIXED, contentType)); } - InputStream input = ctx.getInputStream(); @SuppressWarnings("deprecation") // still has to be backward compatible final int contentLengthInt = ctx.getContentLength(); @@ -960,6 +968,7 @@ : contentLengthInt; // CHECKSTYLE:ON + InputStream input; // N.B. this is eventually closed in MultipartStream processing if (sizeMax >= 0) { if (requestSize != -1 && requestSize > sizeMax) { throw new SizeLimitExceededException( @@ -967,7 +976,8 @@ Long.valueOf(requestSize), Long.valueOf(sizeMax)), requestSize, sizeMax); } - input = new LimitedInputStream(input, sizeMax) { + // N.B. this is eventually closed in MultipartStream processing + input = new LimitedInputStream(ctx.getInputStream(), sizeMax) { @Override protected void raiseError(long pSizeMax, long pCount) throws IOException { @@ -978,6 +988,8 @@ throw new FileUploadIOException(ex); } }; + } else { + input = ctx.getInputStream(); } String charEncoding = headerEncoding; @@ -987,6 +999,7 @@ boundary = getBoundary(contentType); if (boundary == null) { + IOUtils.closeQuietly(input); // avoid possible resource leak throw new FileUploadException("the request was rejected because no multipart boundary was found"); } @@ -994,6 +1007,7 @@ try { multi = new MultipartStream(input, boundary, notifier); } catch (IllegalArgumentException iae) { + IOUtils.closeQuietly(input); // avoid possible resource leak throw new InvalidContentTypeException( format("The boundary specified in the %s header is too long", CONTENT_TYPE), iae); } @@ -1095,6 +1109,7 @@ * @return True, if one or more additional file items * are available, otherwise false. */ + @Override public boolean hasNext() throws FileUploadException, IOException { if (eof) { return false; @@ -1121,6 +1136,7 @@ * @return FileItemStream instance, which provides * access to the next file item. */ + @Override public FileItemStream next() throws FileUploadException, IOException { if (eof || (!itemValid && !hasNext())) { throw new NoSuchElementException(); @@ -1361,7 +1377,7 @@ /** * @deprecated 1.2 Replaced by - * {@code SizeLimitExceededException(String, long, long)} + * {@link #SizeLimitExceededException(String, long, long)} */ @Deprecated public SizeLimitExceededException() { @@ -1370,7 +1386,7 @@ /** * @deprecated 1.2 Replaced by - * {@code #SizeLimitExceededException(String, long, long)} + * {@link #SizeLimitExceededException(String, long, long)} * @param message The exceptions detail message. */ @Deprecated diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileUploadException.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileUploadException.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileUploadException.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileUploadException.java 2018-12-24 06:43:43.000000000 +0000 @@ -21,8 +21,6 @@ /** * Exception for errors encountered while processing the request. - * - * @version $Id$ */ public class FileUploadException extends Exception { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileUpload.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileUpload.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/FileUpload.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/FileUpload.java 2018-12-24 06:43:43.000000000 +0000 @@ -29,8 +29,6 @@ *

How the data for individual parts is stored is determined by the factory * used to create them; a given part may be in memory, on disk, or somewhere * else.

- * - * @version $Id$ */ public class FileUpload extends FileUploadBase { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/InvalidFileNameException.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/InvalidFileNameException.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/InvalidFileNameException.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/InvalidFileNameException.java 2018-12-24 06:43:43.000000000 +0000 @@ -25,8 +25,6 @@ * checks for the extension ".png"), while, depending on the underlying * C library, it might create a file named "foo.exe", as the NUL * character is the string terminator in C. - * - * @version $Id$ */ public class InvalidFileNameException extends RuntimeException { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/MultipartStream.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/MultipartStream.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/MultipartStream.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/MultipartStream.java 2018-12-24 06:43:43.000000000 +0000 @@ -80,8 +80,6 @@ * // a read or write error occurred * } * - * - * @version $Id$ */ public class MultipartStream { @@ -222,12 +220,17 @@ * The amount of data, in bytes, that must be kept in the buffer in order * to detect delimiters reliably. */ - private int keepRegion; + private final int keepRegion; /** * The byte sequence that partitions the stream. */ - private byte[] boundary; + private final byte[] boundary; + + /** + * The table for Knuth-Morris-Pratt search algorithm. + */ + private final int[] boundaryTable; /** * The length of the buffer used for processing the request. @@ -339,12 +342,14 @@ this.notifier = pNotifier; this.boundary = new byte[this.boundaryLength]; + this.boundaryTable = new int[this.boundaryLength + 1]; this.keepRegion = this.boundary.length; System.arraycopy(BOUNDARY_PREFIX, 0, this.boundary, 0, BOUNDARY_PREFIX.length); System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length, boundary.length); + computeBoundaryTable(); head = 0; tail = 0; @@ -502,10 +507,35 @@ throws IllegalBoundaryException { if (boundary.length != boundaryLength - BOUNDARY_PREFIX.length) { throw new IllegalBoundaryException( - "The length of a boundary token can not be changed"); + "The length of a boundary token cannot be changed"); } System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length, boundary.length); + computeBoundaryTable(); + } + + /** + * Compute the table used for Knuth-Morris-Pratt search algorithm. + */ + private void computeBoundaryTable() { + int position = 2; + int candidate = 0; + + boundaryTable[0] = -1; + boundaryTable[1] = 0; + + while (position <= boundaryLength) { + if (boundary[position - 1] == boundary[candidate]) { + boundaryTable[position] = candidate + 1; + candidate++; + position++; + } else if (candidate > 0) { + candidate = boundaryTable[candidate]; + } else { + boundaryTable[position] = 0; + position++; + } + } } /** @@ -589,8 +619,7 @@ */ public int readBodyData(OutputStream output) throws MalformedStreamException, IOException { - final InputStream istream = newInputStream(); - return (int) Streams.copy(istream, output, false); + return (int) Streams.copy(newInputStream(), output, false); // N.B. Streams.copy closes the input stream } /** @@ -629,6 +658,7 @@ // First delimiter may be not preceeded with a CRLF. System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2); boundaryLength = boundary.length - 2; + computeBoundaryTable(); try { // Discard all data up to the delimiter. discardBodyData(); @@ -644,6 +674,7 @@ boundaryLength = boundary.length; boundary[0] = CR; boundary[1] = LF; + computeBoundaryTable(); } } @@ -699,23 +730,20 @@ * not found. */ protected int findSeparator() { - int first; - int match = 0; - int maxpos = tail - boundaryLength; - for (first = head; first <= maxpos && match != boundaryLength; first++) { - first = findByte(boundary[0], first); - if (first == -1 || first > maxpos) { - return -1; - } - for (match = 1; match < boundaryLength; match++) { - if (buffer[first + match] != boundary[match]) { - break; - } + + int bufferPos = this.head; + int tablePos = 0; + + while (bufferPos < this.tail) { + while (tablePos >= 0 && buffer[bufferPos] != boundary[tablePos]) { + tablePos = boundaryTable[tablePos]; + } + bufferPos++; + tablePos++; + if (tablePos == boundaryLength) { + return bufferPos - boundaryLength; } } - if (match == boundaryLength) { - return first - 1; - } return -1; } @@ -1023,6 +1051,7 @@ * * @return True, if the stream is closed, otherwise false. */ + @Override public boolean isClosed() { return closed; } diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/ParameterParser.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/ParameterParser.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/ParameterParser.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/ParameterParser.java 2018-12-24 06:43:43.000000000 +0000 @@ -33,8 +33,6 @@ *

* param1 = value; param2 = "anything goes; really"; param3 *

- * - * @version $Id$ */ public class ParameterParser { @@ -78,8 +76,8 @@ /** * Are there any characters left to parse? * - * @return true if there are unparsed characters, - * false otherwise. + * @return {@code true} if there are unparsed characters, + * {@code false} otherwise. */ private boolean hasChar() { return this.pos < this.len; @@ -90,8 +88,8 @@ * leading and trailing blanks as well as enclosing quotation marks, * when necessary. * - * @param quoted true if quotation marks are expected, - * false otherwise. + * @param quoted {@code true} if quotation marks are expected, + * {@code false} otherwise. * @return the token */ private String getToken(boolean quoted) { @@ -124,8 +122,8 @@ * @param ch the character to test for presense in the array of characters * @param charray the array of characters to test against * - * @return true if the character is present in the array of - * characters, false otherwise. + * @return {@code true} if the character is present in the array of + * characters, {@code false} otherwise. */ private boolean isOneOf(char ch, final char[] charray) { boolean result = false; @@ -195,12 +193,12 @@ } /** - * Returns true if parameter names are to be converted to lower + * Returns {@code true} if parameter names are to be converted to lower * case when name/value pairs are parsed. * - * @return true if parameter names are to be + * @return {@code true} if parameter names are to be * converted to lower case when name/value pairs are parsed. - * Otherwise returns false + * Otherwise returns {@code false} */ public boolean isLowerCaseNames() { return this.lowerCaseNames; @@ -210,9 +208,9 @@ * Sets the flag if parameter names are to be converted to lower case when * name/value pairs are parsed. * - * @param b true if parameter names are to be + * @param b {@code true} if parameter names are to be * converted to lower case when name/value pairs are parsed. - * false otherwise. + * {@code false} otherwise. */ public void setLowerCaseNames(boolean b) { this.lowerCaseNames = b; diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/portlet/package-info.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/portlet/package-info.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/portlet/package-info.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/portlet/package-info.java 2018-12-24 06:43:43.000000000 +0000 @@ -30,7 +30,7 @@ * The following code fragment demonstrates typical usage. *

*
- *       DiskFileItemFactory factory = new DiskFileItemFactory();
+ *        DiskFileItemFactory factory = new DiskFileItemFactory();
  *        // Configure the factory here, if desired.
  *        PortletFileUpload upload = new PortletFileUpload(factory);
  *        // Configure the uploader here, if desired.
diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/portlet/PortletFileUpload.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/portlet/PortletFileUpload.java
--- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/portlet/PortletFileUpload.java	2017-05-30 12:22:29.000000000 +0000
+++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/portlet/PortletFileUpload.java	2018-12-24 06:43:43.000000000 +0000
@@ -45,8 +45,6 @@
  * else.

* * @since FileUpload 1.1 - * - * @version $Id$ */ public class PortletFileUpload extends FileUpload { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java 2018-12-24 06:43:43.000000000 +0000 @@ -31,8 +31,6 @@ * a portlet.

* * @since FileUpload 1.1 - * - * @version $Id$ */ public class PortletRequestContext implements UploadContext { @@ -63,6 +61,7 @@ * * @return The character encoding for the request. */ + @Override public String getCharacterEncoding() { return request.getCharacterEncoding(); } @@ -72,6 +71,7 @@ * * @return The content type of the request. */ + @Override public String getContentType() { return request.getContentType(); } @@ -82,6 +82,7 @@ * @return The content length of the request. * @deprecated 1.3 Use {@link #contentLength()} instead */ + @Override @Deprecated public int getContentLength() { return request.getContentLength(); @@ -93,6 +94,7 @@ * @return The content length of the request. * @since 1.3 */ + @Override public long contentLength() { long size; try { @@ -110,6 +112,7 @@ * * @throws IOException if a problem occurs. */ + @Override public InputStream getInputStream() throws IOException { return request.getPortletInputStream(); } diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/ProgressListener.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/ProgressListener.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/ProgressListener.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/ProgressListener.java 2018-12-24 06:43:43.000000000 +0000 @@ -19,8 +19,6 @@ /** * The {@link ProgressListener} may be used to display a progress bar * or do stuff like that. - * - * @version $Id$ */ public interface ProgressListener { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/RequestContext.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/RequestContext.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/RequestContext.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/RequestContext.java 2018-12-24 06:43:43.000000000 +0000 @@ -25,8 +25,6 @@ * handled by FileUpload, such as servlets and portlets.

* * @since FileUpload 1.1 - * - * @version $Id$ */ public interface RequestContext { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java 2018-12-24 06:43:43.000000000 +0000 @@ -26,8 +26,6 @@ * A servlet context listener, which ensures that the * {@link FileCleaningTracker}'s reaper thread is terminated, * when the web application is destroyed. - * - * @version $Id$ */ public class FileCleanerCleanup implements ServletContextListener { @@ -70,6 +68,7 @@ * @param sce The servlet context, used for calling * {@link #setFileCleaningTracker(ServletContext, FileCleaningTracker)}. */ + @Override public void contextInitialized(ServletContextEvent sce) { setFileCleaningTracker(sce.getServletContext(), new FileCleaningTracker()); @@ -82,6 +81,7 @@ * @param sce The servlet context, used for calling * {@link #getFileCleaningTracker(ServletContext)}. */ + @Override public void contextDestroyed(ServletContextEvent sce) { getFileCleaningTracker(sce.getServletContext()).exitWhenFinished(); } diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java 2018-12-24 06:43:43.000000000 +0000 @@ -42,8 +42,6 @@ *

How the data for individual parts is stored is determined by the factory * used to create them; a given part may be in memory, on disk, or somewhere * else.

- * - * @version $Id$ */ public class ServletFileUpload extends FileUpload { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java 2018-12-24 06:43:43.000000000 +0000 @@ -31,8 +31,6 @@ * an HTTP servlet.

* * @since FileUpload 1.1 - * - * @version $Id$ */ public class ServletRequestContext implements UploadContext { @@ -61,6 +59,7 @@ * * @return The character encoding for the request. */ + @Override public String getCharacterEncoding() { return request.getCharacterEncoding(); } @@ -70,6 +69,7 @@ * * @return The content type of the request. */ + @Override public String getContentType() { return request.getContentType(); } @@ -80,6 +80,7 @@ * @return The content length of the request. * @deprecated 1.3 Use {@link #contentLength()} instead */ + @Override @Deprecated public int getContentLength() { return request.getContentLength(); @@ -91,6 +92,7 @@ * @return The content length of the request. * @since 1.3 */ + @Override public long contentLength() { long size; try { @@ -108,6 +110,7 @@ * * @throws IOException if a problem occurs. */ + @Override public InputStream getInputStream() throws IOException { return request.getInputStream(); } diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/Closeable.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/Closeable.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/Closeable.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/Closeable.java 2018-12-24 06:43:43.000000000 +0000 @@ -20,8 +20,6 @@ /** * Interface of an object, which may be closed. - * - * @version $Id$ */ public interface Closeable { diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java 2018-12-24 06:43:43.000000000 +0000 @@ -31,8 +31,6 @@ * Default implementation of the {@link FileItemHeaders} interface. * * @since 1.2.1 - * - * @version $Id$ */ public class FileItemHeadersImpl implements FileItemHeaders, Serializable { @@ -50,6 +48,7 @@ /** * {@inheritDoc} */ + @Override public String getHeader(String name) { String nameLower = name.toLowerCase(Locale.ENGLISH); List headerValueList = headerNameToValueListMap.get(nameLower); @@ -62,6 +61,7 @@ /** * {@inheritDoc} */ + @Override public Iterator getHeaderNames() { return headerNameToValueListMap.keySet().iterator(); } @@ -69,6 +69,7 @@ /** * {@inheritDoc} */ + @Override public Iterator getHeaders(String name) { String nameLower = name.toLowerCase(Locale.ENGLISH); List headerValueList = headerNameToValueListMap.get(nameLower); diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/LimitedInputStream.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/LimitedInputStream.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/LimitedInputStream.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/LimitedInputStream.java 2018-12-24 06:43:43.000000000 +0000 @@ -23,8 +23,6 @@ /** * An input stream, which limits its data size. This stream is * used, if the content length is unknown. - * - * @version $Id$ */ public abstract class LimitedInputStream extends FilterInputStream implements Closeable { @@ -93,7 +91,7 @@ * * @return the next byte of data, or -1 if the end of the * stream is reached. - * @exception IOException if an I/O error occurs. + * @throws IOException if an I/O error occurs. * @see java.io.FilterInputStream#in */ @Override @@ -122,11 +120,11 @@ * @return the total number of bytes read into the buffer, or * -1 if there is no more data because the end of * the stream has been reached. - * @exception NullPointerException If b is null. - * @exception IndexOutOfBoundsException If off is negative, + * @throws NullPointerException If b is null. + * @throws IndexOutOfBoundsException If off is negative, * len is negative, or len is greater than * b.length - off - * @exception IOException if an I/O error occurs. + * @throws IOException if an I/O error occurs. * @see java.io.FilterInputStream#in */ @Override @@ -145,6 +143,7 @@ * @return True, if the stream is closed, otherwise false. * @throws IOException An I/O error occurred. */ + @Override public boolean isClosed() throws IOException { return closed; } @@ -155,7 +154,7 @@ * This * method simply performs in.close(). * - * @exception IOException if an I/O error occurs. + * @throws IOException if an I/O error occurs. * @see java.io.FilterInputStream#in */ @Override diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java 2018-12-24 06:43:43.000000000 +0000 @@ -212,7 +212,7 @@ } // pull out the character set information (this is the MIME name at this point). - String charset = word.substring(2, charsetPos).toLowerCase(); + String charset = word.substring(2, charsetPos).toLowerCase(Locale.ENGLISH); // now pull out the encoding token the same way. int encodingPos = word.indexOf('?', charsetPos + 1); diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java 2018-12-24 06:43:43.000000000 +0000 @@ -44,7 +44,7 @@ * @param out The output stream used to return the decoded data. * * @return the number of bytes produced. - * @exception IOException + * @throws IOException */ public static int decode(byte[] data, OutputStream out) throws IOException { int off = 0; diff -Nru libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/Streams.java libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/Streams.java --- libcommons-fileupload-java-1.3.3/src/main/java/org/apache/commons/fileupload/util/Streams.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/main/java/org/apache/commons/fileupload/util/Streams.java 2018-12-24 06:43:43.000000000 +0000 @@ -26,8 +26,6 @@ /** * Utility class for working with streams. - * - * @version $Id$ */ public final class Streams { diff -Nru libcommons-fileupload-java-1.3.3/src/site/fml/faq.fml libcommons-fileupload-java-1.4/src/site/fml/faq.fml --- libcommons-fileupload-java-1.3.3/src/site/fml/faq.fml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/fml/faq.fml 2018-12-24 06:43:43.000000000 +0000 @@ -175,41 +175,41 @@ - FileUpload and Flash + FileUpload and Flash - - I have read, that there is a security problem in Commons FileUpload, because there is a class called - DiskFileItem, which can be used for malicious attacks. - - -

- It is true, that this class exists, and can be serialized/deserialized in FileUpload versions, up to, and - including 1.3.2. It is also true, that a malicious attacker can abuse this possibility to create abitraryly - located files (assuming the required permissions) with arbitrary contents, if he gets the opportunity to - provide specially crafted data, which is being deserialized by a Java application, which has either of the - above versions of Commons FileUpload in the classpath, and which puts no limitations on the classes being - deserialized. -

-

- That being said, we (the Apache Commons team) hold the view, that the actual problem is not the DiskFileItem - class, but the "if" in the previous sentence. A Java application should carefully consider, which classes - can be deserialized. A typical approach would be, for example, to provide a blacklist, or whitelist of - packages, and/or classes, which may, or may not be deserialized. -

-

- On the other hand, we acknowledge, that the likelyhood of application container vendors taking such a - simple security measure is extremely low. So, in order to support the Commons Fileupload users, we have - decided to choose a different approach: -

-

- Beginning with 1.3.3, the class DiskFileItem is still implementing the interface java.io.Serializable. - In other words, it still declares itself as serializable, and deserializable to the JVM. In practice, - however, an attempt to deserialize an instance of DiskFileItem will trigger an Exception. In the unlikely - case, that your application depends on the deserialization of DiskFileItems, you can revert to the - previous behaviour by setting the system property "org.apache.commons.fileupload.disk.DiskFileItem.serializable" - to "true". -

-
-
+ + I have read, that there is a security problem in Commons FileUpload, because there is a class called + DiskFileItem, which can be used for malicious attacks. + + +

+ It is true, that this class exists, and can be serialized/deserialized in FileUpload versions, up to, and + including 1.3.2. It is also true, that a malicious attacker can abuse this possibility to create abitraryly + located files (assuming the required permissions) with arbitrary contents, if he gets the opportunity to + provide specially crafted data, which is being deserialized by a Java application, which has either of the + above versions of Commons FileUpload in the classpath, and which puts no limitations on the classes being + deserialized. +

+

+ That being said, we (the Apache Commons team) hold the view, that the actual problem is not the DiskFileItem + class, but the "if" in the previous sentence. A Java application should carefully consider, which classes + can be deserialized. A typical approach would be, for example, to provide a blacklist, or whitelist of + packages, and/or classes, which may, or may not be deserialized. +

+

+ On the other hand, we acknowledge, that the likelyhood of application container vendors taking such a + simple security measure is extremely low. So, in order to support the Commons Fileupload users, we have + decided to choose a different approach: +

+

+ Beginning with 1.3.3, the class DiskFileItem is still implementing the interface java.io.Serializable. + In other words, it still declares itself as serializable, and deserializable to the JVM. In practice, + however, an attempt to deserialize an instance of DiskFileItem will trigger an Exception. In the unlikely + case, that your application depends on the deserialization of DiskFileItems, you can revert to the + previous behaviour by setting the system property "org.apache.commons.fileupload.disk.DiskFileItem.serializable" + to "true". +

+
+
diff -Nru libcommons-fileupload-java-1.3.3/src/site/resources/profile.cobertura libcommons-fileupload-java-1.4/src/site/resources/profile.cobertura --- libcommons-fileupload-java-1.3.3/src/site/resources/profile.cobertura 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/resources/profile.cobertura 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,2 @@ +# This file is intentionally empty. It is only used, because its +# presence activates the generation of a Coberturta report. diff -Nru libcommons-fileupload-java-1.3.3/src/site/site.xml libcommons-fileupload-java-1.4/src/site/site.xml --- libcommons-fileupload-java-1.3.3/src/site/site.xml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/site.xml 2018-12-24 06:43:43.000000000 +0000 @@ -30,12 +30,13 @@ - + + - + diff -Nru libcommons-fileupload-java-1.3.3/src/site/xdoc/download_fileupload.xml libcommons-fileupload-java-1.4/src/site/xdoc/download_fileupload.xml --- libcommons-fileupload-java-1.3.3/src/site/xdoc/download_fileupload.xml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/xdoc/download_fileupload.xml 2018-12-24 07:06:01.000000000 +0000 @@ -31,21 +31,10 @@ | 2) Set the following properties in the component's pom: | | - commons.componentid (required, alphabetic, lower case) | | - commons.release.version (required) | - | - commons.release.name (required) | - | - commons.binary.suffix (optional) | + | - commons.binary.suffix (optional) | | (defaults to "-bin", set to "" for pre-maven2 releases) | - | - commons.release.desc (optional) | - | - commons.release.subdir (optional) | - | | - | - commons.release.2/3.version (conditional) | - | - commons.release.2/3.name (conditional) | - | - commons.release.2/3.binary.suffix (optional) | - | - commons.release.2/3.desc (optional) | - | - commons.release.2/3.subdir (optional) | | | | 3) Example Properties | - | (commons.release.name inherited by parent: | - | ${project.artifactId}-${commons.release.version} | | | | | | math | @@ -57,17 +46,17 @@ Download Apache Commons FileUpload - Apache Commons Documentation Team + Commons Documentation Team

We recommend you use a mirror to download our release - builds, but you must verify the integrity of + builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hours) may not yet - be available from all the mirrors. + be available from the mirrors.

@@ -99,44 +88,39 @@

- It is essential that you - verify the integrity - of downloaded files, preferably using the PGP signature (*.asc files); - failing that using the MD5 hash (*.md5 checksum files). -

-

- The KEYS - file contains the public PGP keys used by Apache Commons developers - to sign releases. + The KEYS + link links to the code signing keys used to sign the product. + The PGP link downloads the OpenPGP compatible signature from our main site. + The SHA256 link downloads the checksum from the main site.

-
+
- - - + + + - - - + + +
commons-fileupload-1.3.3-bin.tar.gzmd5pgpcommons-fileupload-1.4-bin.tar.gzsha256pgp
commons-fileupload-1.3.3-bin.zipmd5pgpcommons-fileupload-1.4-bin.zipsha256pgp
- - - + + + - - - + + +
commons-fileupload-1.3.3-src.tar.gzmd5pgpcommons-fileupload-1.4-src.tar.gzsha256pgp
commons-fileupload-1.3.3-src.zipmd5pgpcommons-fileupload-1.4-src.zipsha256pgp
@@ -147,7 +131,7 @@

diff -Nru libcommons-fileupload-java-1.3.3/src/site/xdoc/index.xml libcommons-fileupload-java-1.4/src/site/xdoc/index.xml --- libcommons-fileupload-java-1.3.3/src/site/xdoc/index.xml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/xdoc/index.xml 2018-12-24 07:06:01.000000000 +0000 @@ -59,20 +59,34 @@
  • User Guide
  • Streaming API
  • Frequently Asked Questions
  • -
  • JavaDoc API
  • +
  • Javadoc API (Latest release)
  • +
  • Javadoc API (Latest development)
  • Project Reports
  • +
  • Release Notes
  • You can also browse the Subversion repository.

    -

    FileUpload 1.3.2 - 26 May 2016

    +

    FileUpload 1.4 - 23 December 2018

    • Download the binary and source distributions from a mirror site here
    +

    FileUpload 1.3.3 - 13 June 2017

    +
      +
    • Download the binary and source distributions from a mirror site + here +
    • +
    +

    FileUpload 1.3.2 - 26 May 2016

    +
      +
    • Download the binary and source distributions from the archive site + here +
    • +

    FileUpload 1.3.1 - 7 February 2014

    • Download the binary and source distributions from the archive site @@ -81,13 +95,13 @@

    FileUpload 1.3 - 27 March 2013

      -
    • Download the binary and source distributions from a mirror site +
    • Download the binary and source distributions from the archive site here

    FileUpload 1.2.2 - 29 July 2010

      -
    • Download the binary and source distributions from a mirror site +
    • Download the binary and source distributions from the archive site here
    diff -Nru libcommons-fileupload-java-1.3.3/src/site/xdoc/security-reports.xml libcommons-fileupload-java-1.4/src/site/xdoc/security-reports.xml --- libcommons-fileupload-java-1.3.3/src/site/xdoc/security-reports.xml 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/xdoc/security-reports.xml 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,137 @@ + + + + + Commons FileUpload Security Reports + Commons Documentation Team + + +
    +

    This page lists all security vulnerabilities fixed in + released versions of Apache Commons FileUpload. Each + vulnerability is given a security impact rating by the + development team - please note that this rating may vary from + platform to platform. We also list the versions of Commons + FileUpload the flaw is known to affect, and where a flaw has not + been verified list the version with a question mark.

    + +

    Please note that binary patches are never provided. If you + need to apply a source code patch, use the building + instructions for the Commons FileUpload version that you are + using.

    + +

    If you need help on building Commons FileUpload or other help + on following the instructions to mitigate the known + vulnerabilities listed here, please send your questions to the + public Commons Users mailing + list.

    + +

    If you have encountered an unlisted security vulnerability + or other unexpected behaviour that has security impact, or if + the descriptions here are incomplete, please report them + privately to the Apache Security Team. Thank you.

    + +

    For information about reporting or asking questions about + security problems, please see the security page + of the Apache Commons project.

    + + +

    + Regarding potential security problems with the class called DiskFileItem, + it is true, that this class exists, and can be serialized/deserialized in FileUpload versions, up to, and + including 1.3.2. It is also true, that a malicious attacker can abuse this possibility to create abitraryly + located files (assuming the required permissions) with arbitrary contents, if he gets the opportunity to + provide specially crafted data, which is being deserialized by a Java application, which has either of the + above versions of Commons FileUpload in the classpath, and which puts no limitations on the classes being + deserialized. +

    +

    + That being said, we (the Apache Commons team) hold the view, that the actual problem is not the DiskFileItem + class, but the "if" in the previous sentence. A Java application should carefully consider, which classes + can be deserialized. A typical approach would be, for example, to provide a blacklist, or whitelist of + packages, and/or classes, which may, or may not be deserialized. +

    +

    + On the other hand, we acknowledge, that the likelyhood of application container vendors taking such a + simple security measure is extremely low. So, in order to support the Commons Fileupload users, we have + decided to choose a different approach: +

    +

    + Beginning with 1.3.3, the class DiskFileItem is still implementing the interface java.io.Serializable. + In other words, it still declares itself as serializable, and deserializable to the JVM. In practice, + however, an attempt to deserialize an instance of DiskFileItem will trigger an Exception. In the unlikely + case, that your application depends on the deserialization of DiskFileItems, you can revert to the + previous behaviour by setting the system property "org.apache.commons.fileupload.disk.DiskFileItem.serializable" + to "true". +

    +
    + + +

    Low: Denial of Service CVE-2016-3092

    + +

    Specially crafted input can trigger a DoS (slow uploads), if the size of the MIME + boundary is close to the size of the buffer in MultipartStream. This is also fixed + for Apache Tomcat.

    + +

    This was fixed in revisions + 1743480.

    + +

    Affects: 1.0? - 1.3.1

    +
    + + +

    Low: Denial of Service CVE-2014-0050

    + +

    MultipartStream.java in Apache Commons FileUpload before 1.3.1, as used in + Apache Tomcat, + JBoss Web, and other products, allows remote attackers to cause a denial of service (infinite + loop and CPU consumption) via a crafted Content-Type header that bypasses a loop's intended + exit conditions.

    + +

    This was fixed in revisions + 1565143.

    + +

    Affects: 1.0? - 1.3

    +
    + + + +

    Low: Improved Documentation for Multitenancy CVE-2013-0248

    + +

    Update the Javadoc and documentation to make it clear that setting a repository + is required for a secure configuration if there are local, untrusted users.

    + +

    This was fixed in revisions + 1453273.

    + +

    Affects: 1.0 - 1.2.2

    +
    + +
    + +
    +

    Please report any errors or omissions to the dev mailing list.

    +
    + +
    diff -Nru libcommons-fileupload-java-1.3.3/src/site/xdoc/streaming.xml libcommons-fileupload-java-1.4/src/site/xdoc/streaming.xml --- libcommons-fileupload-java-1.3.3/src/site/xdoc/streaming.xml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/xdoc/streaming.xml 2018-12-24 06:43:43.000000000 +0000 @@ -27,14 +27,14 @@

    The traditional API, which is described in the User - Guide, assumes, that file items must be stored somewhere, before + Guide, assumes that file items must be stored somewhere before they are actually accessable by the user. This approach is convenient, because it allows easy access to an items contents. On the other hand, it is memory and time consuming.

    The streaming API allows you to trade a little bit of convenience for - optimal performance and and a low memory profile. Additionally, the + optimal performance and a low memory profile. Additionally, the API is more lightweight, thus easier to understand.

    @@ -42,7 +42,7 @@

    Again, the FileUpload class is used for accessing the - form fields and fields in the order, in which they have been sent + form fields and fields in the order in which they have been sent by the client. However, the FileItemFactory is completely ignored.

    @@ -50,7 +50,7 @@

    - First of all, do not forget to ensure, that a request actually is a + First of all, do not forget to ensure that a request actually is a a file upload request. This is typically done using the same static method, which you already know from the traditional API.

    @@ -68,7 +68,7 @@ while (iter.hasNext()) { FileItemStream item = iter.next(); String name = item.getFieldName(); - InputStream stream = item.openStream(); + InputStream stream = item.getInputStream(); if (item.isFormField()) { System.out.println("Form field " + name + " with value " + Streams.asString(stream) + " detected."); diff -Nru libcommons-fileupload-java-1.3.3/src/site/xdoc/using.xml libcommons-fileupload-java-1.4/src/site/xdoc/using.xml --- libcommons-fileupload-java-1.3.3/src/site/xdoc/using.xml 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/site/xdoc/using.xml 2018-12-24 06:43:43.000000000 +0000 @@ -284,8 +284,8 @@

    Such temporary files are deleted automatically, if they are no longer - used (more precisely, if the corresponding instance of java.io.File - is garbage collected. This is done silently by the org.apache.commons.io.FileCleaner + used (more precisely, if the corresponding instance of DiskFileItem + is garbage collected. This is done silently by the org.apache.commons.io.FileCleanerTracker class, which starts a reaper thread.

    @@ -426,7 +426,7 @@ Hopefully this page has provided you with a good idea of how to use FileUpload in your own applications. For more detail on the methods introduced here, as well as other available methods, you should refer - to the JavaDocs. + to the Javadocs.

    The usage described here should satisfy a large majority of file upload diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/Constants.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/Constants.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/Constants.java 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/Constants.java 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload; + +/** + * Constants used for testing. + * + * @since 1.4 + */ +public final class Constants { + + /** + * The content type used in several tests. + */ + public static final String CONTENT_TYPE = "multipart/form-data; boundary=---1234"; + + private Constants() {} +} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -27,13 +27,12 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; +import org.apache.commons.io.FileUtils; import org.junit.Test; /** * Unit tests for {@link org.apache.commons.fileupload.DefaultFileItem}. - * - * @version $Id$ */ @SuppressWarnings({"deprecation", "javadoc"}) // unit tests for deprecated class public class DefaultFileItemTest { @@ -142,11 +141,11 @@ * configured threshold, where a specific repository is configured. */ @Test - public void testAboveThresholdSpecifiedRepository() { + public void testAboveThresholdSpecifiedRepository() throws IOException { String tempPath = System.getProperty("java.io.tmpdir"); String tempDirName = "testAboveThresholdSpecifiedRepository"; File tempDir = new File(tempPath, tempDirName); - tempDir.mkdir(); + FileUtils.forceMkdir(tempDir); doTestAboveThreshold(tempDir); assertTrue(tempDir.delete()); } diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/DiskFileItemSerializeTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/DiskFileItemSerializeTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/DiskFileItemSerializeTest.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/DiskFileItemSerializeTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -30,22 +30,38 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; -import org.apache.commons.fileupload.disk.DiskFileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Before; import org.junit.Test; - /** * Serialization Unit tests for * {@link org.apache.commons.fileupload.disk.DiskFileItem}. - * - * @version $Id$ */ public class DiskFileItemSerializeTest { - private static final String ERRMSG_DISKFILEITEM_DESERIALIZED = "Property org.apache.commons.fileupload.disk.DiskFileItem.serializable is not true, rejecting to deserialize a DiskFileItem."; + // Use a private repo to catch any files left over by tests + private static final File REPO = new File(System.getProperty("java.io.tmpdir"), "diskfileitemrepo"); + + @Before + public void setUp() throws Exception { + if (REPO.exists()) { + FileUtils.deleteDirectory(REPO); + } + FileUtils.forceMkdir(REPO); + } + + @After + public void tearDown() throws IOException { + for(File file : FileUtils.listFiles(REPO, null, true)) { + System.out.println("Found leftover file " + file); + } + FileUtils.deleteDirectory(REPO); + } - /** + /** * Content type for regular form items. */ private static final String textContentType = "text/plain"; @@ -65,31 +81,22 @@ assertTrue("Initial: in memory", item.isInMemory()); assertEquals("Initial: size", item.getSize(), testFieldValueBytes.length); compareBytes("Initial", item.get(), testFieldValueBytes); - - // Serialize & Deserialize - FileItem newItem = (FileItem)serializeDeserialize(item); - - // Test deserialized content is as expected - assertTrue("Check in memory", newItem.isInMemory()); - compareBytes("Check", testFieldValueBytes, newItem.get()); - - // Compare FileItem's (except byte[]) - compareFileItems(item, newItem); + item.delete(); } - + /** * Helper method to test creation of a field. */ private void testInMemoryObject(byte[] testFieldValueBytes) { - testInMemoryObject(testFieldValueBytes, null); + testInMemoryObject(testFieldValueBytes, REPO); } - + /** * Test creation of a field for which the amount of data falls below the * configured threshold. */ @Test - public void testBelowThreshold() throws Exception { + public void testBelowThreshold() { // Create the FileItem byte[] testFieldValueBytes = createContentBytes(threshold - 1); testInMemoryObject(testFieldValueBytes); @@ -100,7 +107,7 @@ * configured threshold. */ @Test - public void testThreshold() throws Exception { + public void testThreshold() { // Create the FileItem byte[] testFieldValueBytes = createContentBytes(threshold); testInMemoryObject(testFieldValueBytes); @@ -111,7 +118,7 @@ * configured threshold. */ @Test - public void testAboveThreshold() throws Exception { + public void testAboveThreshold() { // Create the FileItem byte[] testFieldValueBytes = createContentBytes(threshold + 1); FileItem item = createFileItem(testFieldValueBytes); @@ -121,28 +128,19 @@ assertEquals("Initial: size", item.getSize(), testFieldValueBytes.length); compareBytes("Initial", item.get(), testFieldValueBytes); - // Serialize & Deserialize - FileItem newItem = (FileItem)serializeDeserialize(item); - - // Test deserialized content is as expected - assertFalse("Check in memory", newItem.isInMemory()); - compareBytes("Check", testFieldValueBytes, newItem.get()); - - // Compare FileItem's (except byte[]) - compareFileItems(item, newItem); + item.delete(); } - + /** * Test serialization and deserialization when repository is not null. */ @Test - public void testValidRepository() throws Exception { + public void testValidRepository() { // Create the FileItem byte[] testFieldValueBytes = createContentBytes(threshold); - File repository = new File(System.getProperty("java.io.tmpdir")); - testInMemoryObject(testFieldValueBytes, repository); + testInMemoryObject(testFieldValueBytes, REPO); } - + /** * Test deserialization fails when repository is not valid. */ @@ -150,38 +148,21 @@ public void testInvalidRepository() throws Exception { // Create the FileItem byte[] testFieldValueBytes = createContentBytes(threshold); - File repository = new File(System.getProperty("java.io.tmpdir") + "file"); + File repository = new File(System.getProperty("java.io.tmpdir"), "file"); FileItem item = createFileItem(testFieldValueBytes, repository); deserialize(serialize(item)); } - + /** * Test deserialization fails when repository contains a null character. */ - @Test + @Test(expected=IOException.class) public void testInvalidRepositoryWithNullChar() throws Exception { // Create the FileItem byte[] testFieldValueBytes = createContentBytes(threshold); - File repository = new File(System.getProperty("java.io.tmpdir") + "\0"); + File repository = new File(System.getProperty("java.io.tmpdir"), "\0"); FileItem item = createFileItem(testFieldValueBytes, repository); - try { - deserialize(serialize(item)); - fail("Expected Exception"); - } catch (IllegalStateException e) { - assertEquals(ERRMSG_DISKFILEITEM_DESERIALIZED, e.getMessage()); - } - System.setProperty(DiskFileItem.SERIALIZABLE_PROPERTY, "true"); - } - - /** - * Compare FileItem's (except the byte[] content) - */ - private void compareFileItems(FileItem origItem, FileItem newItem) { - assertTrue("Compare: is in Memory", origItem.isInMemory() == newItem.isInMemory()); - assertTrue("Compare: is Form Field", origItem.isFormField() == newItem.isFormField()); - assertEquals("Compare: Field Name", origItem.getFieldName(), newItem.getFieldName()); - assertEquals("Compare: Content Type", origItem.getContentType(), newItem.getContentType()); - assertEquals("Compare: File Name", origItem.getName(), newItem.getName()); + deserialize(serialize(item)); } /** @@ -236,14 +217,14 @@ return item; } - + /** * Create a FileItem with the specfied content bytes. */ private FileItem createFileItem(byte[] contentBytes) { - return createFileItem(contentBytes, null); + return createFileItem(contentBytes, REPO); } - + /** * Do serialization */ @@ -255,7 +236,7 @@ oos.close(); return baos; } - + /** * Do deserialization */ @@ -269,28 +250,4 @@ return result; } - - /** - * Do serialization and deserialization. - */ - private Object serializeDeserialize(Object target) { - // Serialize the test object - ByteArrayOutputStream baos = null; - try { - baos = serialize(target); - } catch (Exception e) { - fail("Exception during serialization: " + e); - } - - // Deserialize the test object - Object result = null; - try { - result = deserialize(baos); - } catch (Exception e) { - fail("Exception during deserialization: " + e); - } - - return result; - } - } diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload; + +import static org.junit.Assert.fail; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test for {@link DiskFileUpload}. Remove when deprecated class is removed. + * + * @since 1.4 + */ +@SuppressWarnings({"deprecation"}) // unit tests for deprecated class +public class DiskFileUploadTest { + + private DiskFileUpload upload; + + @Before + public void setUp() { + upload = new DiskFileUpload(); + } + + @Test + public void testWithInvalidRequest() { + HttpServletRequest req = HttpServletRequestFactory.createInvalidHttpServletRequest(); + + try { + upload.parseRequest(req); + fail("testWithInvalidRequest: expected exception was not thrown"); + } catch (FileUploadException expected) { + // this exception is expected + } + } + + @Test + public void testWithNullContentType() { + HttpServletRequest req = HttpServletRequestFactory.createHttpServletRequestWithNullContentType(); + + try { + upload.parseRequest(req); + fail("testWithNullContentType: expected exception was not thrown"); + } catch (DiskFileUpload.InvalidContentTypeException expected) { + // this exception is expected + } catch (FileUploadException unexpected) { + fail("testWithNullContentType: unexpected exception was thrown"); + } + } + +} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/FileItemHeadersTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/FileItemHeadersTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/FileItemHeadersTest.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/FileItemHeadersTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -29,8 +29,6 @@ /** * Unit tests {@link FileItemHeaders} and * {@link FileItemHeadersImpl}. - * - * @version $Id$ */ public class FileItemHeadersTest { diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/FileUploadTestCase.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/FileUploadTestCase.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/FileUploadTestCase.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/FileUploadTestCase.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.fileupload; - -import java.io.UnsupportedEncodingException; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; - -/** - * Base class for deriving test cases. - * - * @version $Id$ - */ -public abstract class FileUploadTestCase { - - protected static final String CONTENT_TYPE = "multipart/form-data; boundary=---1234"; - - protected List parseUpload(byte[] bytes) throws FileUploadException { - return parseUpload(bytes, CONTENT_TYPE); - } - - protected List parseUpload(byte[] bytes, String contentType) throws FileUploadException { - ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); - HttpServletRequest request = new MockHttpServletRequest(bytes, contentType); - - List fileItems = upload.parseRequest(request); - return fileItems; - } - - protected List parseUpload(String content) - throws UnsupportedEncodingException, FileUploadException { - byte[] bytes = content.getBytes("US-ASCII"); - return parseUpload(bytes, CONTENT_TYPE); - } - -} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/FileUploadTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/FileUploadTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/FileUploadTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/FileUploadTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,399 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.List; + +import org.apache.commons.fileupload.portlet.PortletFileUploadTest; +import org.apache.commons.fileupload.servlet.ServletFileUploadTest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** + * Common tests for implementations of {@link FileUpload}. This is a parameterized test. + * Tests must be valid and common to all implementations of FileUpload added as parameter + * in this class. + * + * @see ServletFileUploadTest + * @see PortletFileUploadTest + * @since 1.4 + */ +@RunWith(Parameterized.class) +public class FileUploadTest { + + /** + * @return {@link FileUpload} classes under test. + */ + @Parameters(name="{0}") + public static Iterable data() { + return Util.fileUploadImplementations(); + } + + /** + * Current parameterized FileUpload. + */ + @Parameter + public FileUpload upload; + + // --- Test methods common to all implementations of a FileUpload + + @Test + public void testFileUpload() + throws IOException, FileUploadException { + List fileItems = Util.parseUpload(upload, + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + + "Content-Type: text/whatever\r\n" + + "\r\n" + + "This is the content of the file\n" + + "\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"field\"\r\n" + + "\r\n" + + "fieldValue\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value1\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value2\r\n" + + "-----1234--\r\n"); + assertEquals(4, fileItems.size()); + + FileItem file = fileItems.get(0); + assertEquals("file", file.getFieldName()); + assertFalse(file.isFormField()); + assertEquals("This is the content of the file\n", file.getString()); + assertEquals("text/whatever", file.getContentType()); + assertEquals("foo.tab", file.getName()); + + FileItem field = fileItems.get(1); + assertEquals("field", field.getFieldName()); + assertTrue(field.isFormField()); + assertEquals("fieldValue", field.getString()); + + FileItem multi0 = fileItems.get(2); + assertEquals("multi", multi0.getFieldName()); + assertTrue(multi0.isFormField()); + assertEquals("value1", multi0.getString()); + + FileItem multi1 = fileItems.get(3); + assertEquals("multi", multi1.getFieldName()); + assertTrue(multi1.isFormField()); + assertEquals("value2", multi1.getString()); + } + + @Test + public void testFilenameCaseSensitivity() + throws IOException, FileUploadException { + List fileItems = Util.parseUpload(upload, + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"FiLe\"; filename=\"FOO.tab\"\r\n" + + "Content-Type: text/whatever\r\n" + + "\r\n" + + "This is the content of the file\n" + + "\r\n" + + "-----1234--\r\n"); + assertEquals(1, fileItems.size()); + + FileItem file = fileItems.get(0); + assertEquals("FiLe", file.getFieldName()); + assertEquals("FOO.tab", file.getName()); + } + + /** + * This is what the browser does if you submit the form without choosing a file. + */ + @Test + public void testEmptyFile() + throws UnsupportedEncodingException, FileUploadException { + List fileItems = Util.parseUpload (upload, + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"file\"; filename=\"\"\r\n" + + "\r\n" + + "\r\n" + + "-----1234--\r\n"); + assertEquals(1, fileItems.size()); + + FileItem file = fileItems.get(0); + assertFalse(file.isFormField()); + assertEquals("", file.getString()); + assertEquals("", file.getName()); + } + + /** + * Internet Explorer 5 for the Mac has a bug where the carriage + * return is missing on any boundary line immediately preceding + * an input with type=image. (type=submit does not have the bug.) + */ + @Test + public void testIE5MacBug() + throws UnsupportedEncodingException, FileUploadException { + List fileItems = Util.parseUpload(upload, + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"field1\"\r\n" + + "\r\n" + + "fieldValue\r\n" + + "-----1234\n" + // NOTE \r missing + "Content-Disposition: form-data; name=\"submitName.x\"\r\n" + + "\r\n" + + "42\r\n" + + "-----1234\n" + // NOTE \r missing + "Content-Disposition: form-data; name=\"submitName.y\"\r\n" + + "\r\n" + + "21\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"field2\"\r\n" + + "\r\n" + + "fieldValue2\r\n" + + "-----1234--\r\n"); + + assertEquals(4, fileItems.size()); + + FileItem field1 = fileItems.get(0); + assertEquals("field1", field1.getFieldName()); + assertTrue(field1.isFormField()); + assertEquals("fieldValue", field1.getString()); + + FileItem submitX = fileItems.get(1); + assertEquals("submitName.x", submitX.getFieldName()); + assertTrue(submitX.isFormField()); + assertEquals("42", submitX.getString()); + + FileItem submitY = fileItems.get(2); + assertEquals("submitName.y", submitY.getFieldName()); + assertTrue(submitY.isFormField()); + assertEquals("21", submitY.getString()); + + FileItem field2 = fileItems.get(3); + assertEquals("field2", field2.getFieldName()); + assertTrue(field2.isFormField()); + assertEquals("fieldValue2", field2.getString()); + } + + /** + * Test for FILEUPLOAD-62 + */ + @Test + public void testFILEUPLOAD62() throws Exception { + final String contentType = "multipart/form-data; boundary=AaB03x"; + final String request = + "--AaB03x\r\n" + + "content-disposition: form-data; name=\"field1\"\r\n" + + "\r\n" + + "Joe Blow\r\n" + + "--AaB03x\r\n" + + "content-disposition: form-data; name=\"pics\"\r\n" + + "Content-type: multipart/mixed; boundary=BbC04y\r\n" + + "\r\n" + + "--BbC04y\r\n" + + "Content-disposition: attachment; filename=\"file1.txt\"\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "... contents of file1.txt ...\r\n" + + "--BbC04y\r\n" + + "Content-disposition: attachment; filename=\"file2.gif\"\r\n" + + "Content-type: image/gif\r\n" + + "Content-Transfer-Encoding: binary\r\n" + + "\r\n" + + "...contents of file2.gif...\r\n" + + "--BbC04y--\r\n" + + "--AaB03x--"; + List fileItems = Util.parseUpload(upload, request.getBytes("US-ASCII"), contentType); + assertEquals(3, fileItems.size()); + FileItem item0 = fileItems.get(0); + assertEquals("field1", item0.getFieldName()); + assertNull(item0.getName()); + assertEquals("Joe Blow", new String(item0.get())); + FileItem item1 = fileItems.get(1); + assertEquals("pics", item1.getFieldName()); + assertEquals("file1.txt", item1.getName()); + assertEquals("... contents of file1.txt ...", new String(item1.get())); + FileItem item2 = fileItems.get(2); + assertEquals("pics", item2.getFieldName()); + assertEquals("file2.gif", item2.getName()); + assertEquals("...contents of file2.gif...", new String(item2.get())); + } + + /** + * Test for FILEUPLOAD-111 + */ + @Test + public void testFoldedHeaders() + throws IOException, FileUploadException { + List fileItems = Util.parseUpload(upload, "-----1234\r\n" + + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + + "Content-Type: text/whatever\r\n" + + "\r\n" + + "This is the content of the file\n" + + "\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; \r\n" + + "\tname=\"field\"\r\n" + + "\r\n" + + "fieldValue\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data;\r\n" + + " name=\"multi\"\r\n" + + "\r\n" + + "value1\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value2\r\n" + + "-----1234--\r\n"); + assertEquals(4, fileItems.size()); + + FileItem file = fileItems.get(0); + assertEquals("file", file.getFieldName()); + assertFalse(file.isFormField()); + assertEquals("This is the content of the file\n", file.getString()); + assertEquals("text/whatever", file.getContentType()); + assertEquals("foo.tab", file.getName()); + + FileItem field = fileItems.get(1); + assertEquals("field", field.getFieldName()); + assertTrue(field.isFormField()); + assertEquals("fieldValue", field.getString()); + + FileItem multi0 = fileItems.get(2); + assertEquals("multi", multi0.getFieldName()); + assertTrue(multi0.isFormField()); + assertEquals("value1", multi0.getString()); + + FileItem multi1 = fileItems.get(3); + assertEquals("multi", multi1.getFieldName()); + assertTrue(multi1.isFormField()); + assertEquals("value2", multi1.getString()); + } + + /** + * Test case for + */ + @Test + public void testFileUpload130() + throws Exception { + final String[] headerNames = new String[] + { + "SomeHeader", "OtherHeader", "YetAnotherHeader", "WhatAHeader" + }; + final String[] headerValues = new String[] + { + "present", "Is there", "Here", "Is That" + }; + List fileItems = Util.parseUpload(upload, + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + + "Content-Type: text/whatever\r\n" + + headerNames[0] + ": " + headerValues[0] + "\r\n" + + "\r\n" + + "This is the content of the file\n" + + "\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; \r\n" + + "\tname=\"field\"\r\n" + + headerNames[1] + ": " + headerValues[1] + "\r\n" + + "\r\n" + + "fieldValue\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data;\r\n" + + " name=\"multi\"\r\n" + + headerNames[2] + ": " + headerValues[2] + "\r\n" + + "\r\n" + + "value1\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + headerNames[3] + ": " + headerValues[3] + "\r\n" + + "\r\n" + + "value2\r\n" + + "-----1234--\r\n"); + assertEquals(4, fileItems.size()); + + FileItem file = fileItems.get(0); + assertHeaders(headerNames, headerValues, file, 0); + + FileItem field = fileItems.get(1); + assertHeaders(headerNames, headerValues, field, 1); + + FileItem multi0 = fileItems.get(2); + assertHeaders(headerNames, headerValues, multi0, 2); + + FileItem multi1 = fileItems.get(3); + assertHeaders(headerNames, headerValues, multi1, 3); + } + + /** + * Test for FILEUPLOAD-239 + */ + @Test + public void testContentTypeAttachment() + throws IOException, FileUploadException { + List fileItems = Util.parseUpload(upload, + "-----1234\r\n" + + "content-disposition: form-data; name=\"field1\"\r\n" + + "\r\n" + + "Joe Blow\r\n" + + "-----1234\r\n" + + "content-disposition: form-data; name=\"pics\"\r\n" + + "Content-type: multipart/mixed, boundary=---9876\r\n" + + "\r\n" + + "-----9876\r\n" + + "Content-disposition: attachment; filename=\"file1.txt\"\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "... contents of file1.txt ...\r\n" + + "-----9876--\r\n" + + "-----1234--\r\n"); + assertEquals(2, fileItems.size()); + + FileItem field = fileItems.get(0); + assertEquals("field1", field.getFieldName()); + assertTrue(field.isFormField()); + assertEquals("Joe Blow", field.getString()); + + FileItem file = fileItems.get(1); + assertEquals("pics", file.getFieldName()); + assertFalse(file.isFormField()); + assertEquals("... contents of file1.txt ...", file.getString()); + assertEquals("text/plain", file.getContentType()); + assertEquals("file1.txt", file.getName()); + } + + private void assertHeaders(String[] pHeaderNames, String[] pHeaderValues, + FileItem pItem, int pIndex) { + for (int i = 0; i < pHeaderNames.length; i++) { + final String value = pItem.getHeaders().getHeader(pHeaderNames[i]); + if (i == pIndex) { + assertEquals(pHeaderValues[i], value); + } else { + assertNull(value); + } + } + } +} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/HttpServletRequestFactory.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/HttpServletRequestFactory.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/HttpServletRequestFactory.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/HttpServletRequestFactory.java 2018-12-24 06:43:43.000000000 +0000 @@ -18,9 +18,6 @@ import javax.servlet.http.HttpServletRequest; -/** - * @version $Id$ - */ final class HttpServletRequestFactory { static public HttpServletRequest createHttpServletRequestWithNullContentType() { diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/MockHttpServletRequest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/MockHttpServletRequest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/MockHttpServletRequest.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/MockHttpServletRequest.java 2018-12-24 06:43:43.000000000 +0000 @@ -32,16 +32,13 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -/** - * @version $Id$ - */ -class MockHttpServletRequest implements HttpServletRequest { +public class MockHttpServletRequest implements HttpServletRequest { private final InputStream m_requestData; private long length; - private String m_strContentType; + private final String m_strContentType; private int readLimit = -1; @@ -75,6 +72,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getAuthType() */ + @Override public String getAuthType() { return null; } @@ -82,6 +80,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getCookies() */ + @Override public Cookie[] getCookies() { return null; } @@ -89,6 +88,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getDateHeader(String) */ + @Override public long getDateHeader(String arg0) { return 0; } @@ -96,6 +96,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getHeader(String) */ + @Override public String getHeader(String headerName) { return m_headers.get(headerName); } @@ -103,6 +104,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getHeaders(String) */ + @Override public Enumeration getHeaders(String arg0) { // todo - implement return null; @@ -111,6 +113,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getHeaderNames() */ + @Override public Enumeration getHeaderNames() { // todo - implement return null; @@ -119,6 +122,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getIntHeader(String) */ + @Override public int getIntHeader(String arg0) { return 0; } @@ -126,6 +130,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getMethod() */ + @Override public String getMethod() { return null; } @@ -133,6 +138,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getPathInfo() */ + @Override public String getPathInfo() { return null; } @@ -140,6 +146,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getPathTranslated() */ + @Override public String getPathTranslated() { return null; } @@ -147,6 +154,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getContextPath() */ + @Override public String getContextPath() { return null; } @@ -154,6 +162,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getQueryString() */ + @Override public String getQueryString() { return null; } @@ -161,6 +170,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getRemoteUser() */ + @Override public String getRemoteUser() { return null; } @@ -168,6 +178,7 @@ /** * @see javax.servlet.http.HttpServletRequest#isUserInRole(String) */ + @Override public boolean isUserInRole(String arg0) { return false; } @@ -175,6 +186,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() */ + @Override public Principal getUserPrincipal() { return null; } @@ -182,6 +194,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId() */ + @Override public String getRequestedSessionId() { return null; } @@ -189,6 +202,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getRequestURI() */ + @Override public String getRequestURI() { return null; } @@ -196,6 +210,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getRequestURL() */ + @Override public StringBuffer getRequestURL() { return null; } @@ -203,6 +218,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getServletPath() */ + @Override public String getServletPath() { return null; } @@ -210,6 +226,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getSession(boolean) */ + @Override public HttpSession getSession(boolean arg0) { return null; } @@ -217,6 +234,7 @@ /** * @see javax.servlet.http.HttpServletRequest#getSession() */ + @Override public HttpSession getSession() { return null; } @@ -224,6 +242,7 @@ /** * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid() */ + @Override public boolean isRequestedSessionIdValid() { return false; } @@ -231,6 +250,7 @@ /** * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie() */ + @Override public boolean isRequestedSessionIdFromCookie() { return false; } @@ -238,6 +258,7 @@ /** * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL() */ + @Override public boolean isRequestedSessionIdFromURL() { return false; } @@ -246,6 +267,7 @@ * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl() * @deprecated */ + @Override @Deprecated public boolean isRequestedSessionIdFromUrl() { return false; @@ -254,6 +276,7 @@ /** * @see javax.servlet.ServletRequest#getAttribute(String) */ + @Override public Object getAttribute(String arg0) { return null; } @@ -261,6 +284,7 @@ /** * @see javax.servlet.ServletRequest#getAttributeNames() */ + @Override public Enumeration getAttributeNames() { return null; } @@ -268,6 +292,7 @@ /** * @see javax.servlet.ServletRequest#getCharacterEncoding() */ + @Override public String getCharacterEncoding() { return null; } @@ -275,6 +300,7 @@ /** * @see javax.servlet.ServletRequest#setCharacterEncoding(String) */ + @Override public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { } @@ -282,6 +308,7 @@ /** * @see javax.servlet.ServletRequest#getContentLength() */ + @Override public int getContentLength() { int iLength = 0; @@ -306,6 +333,7 @@ /** * @see javax.servlet.ServletRequest#getContentType() */ + @Override public String getContentType() { return m_strContentType; } @@ -313,6 +341,7 @@ /** * @see javax.servlet.ServletRequest#getInputStream() */ + @Override public ServletInputStream getInputStream() throws IOException { ServletInputStream sis = new MyServletInputStream(m_requestData, readLimit); return sis; @@ -330,6 +359,7 @@ /** * @see javax.servlet.ServletRequest#getParameter(String) */ + @Override public String getParameter(String arg0) { return null; } @@ -337,6 +367,7 @@ /** * @see javax.servlet.ServletRequest#getParameterNames() */ + @Override public Enumeration getParameterNames() { return null; } @@ -344,6 +375,7 @@ /** * @see javax.servlet.ServletRequest#getParameterValues(String) */ + @Override public String[] getParameterValues(String arg0) { return null; } @@ -351,6 +383,7 @@ /** * @see javax.servlet.ServletRequest#getParameterMap() */ + @Override public Map getParameterMap() { return null; } @@ -358,6 +391,7 @@ /** * @see javax.servlet.ServletRequest#getProtocol() */ + @Override public String getProtocol() { return null; } @@ -365,6 +399,7 @@ /** * @see javax.servlet.ServletRequest#getScheme() */ + @Override public String getScheme() { return null; } @@ -372,6 +407,7 @@ /** * @see javax.servlet.ServletRequest#getServerName() */ + @Override public String getServerName() { return null; } @@ -379,6 +415,7 @@ /** * @see javax.servlet.ServletRequest#getLocalName() */ + @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalName() { return null; @@ -387,6 +424,7 @@ /** * @see javax.servlet.ServletRequest#getServerPort() */ + @Override public int getServerPort() { return 0; } @@ -394,6 +432,7 @@ /** * @see javax.servlet.ServletRequest#getLocalPort() */ + @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getLocalPort() { return 0; @@ -402,6 +441,7 @@ /** * @see javax.servlet.ServletRequest#getRemotePort() */ + @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getRemotePort() { return 0; @@ -410,6 +450,7 @@ /** * @see javax.servlet.ServletRequest#getReader() */ + @Override public BufferedReader getReader() throws IOException { return null; } @@ -417,6 +458,7 @@ /** * @see javax.servlet.ServletRequest#getRemoteAddr() */ + @Override public String getRemoteAddr() { return null; } @@ -424,6 +466,7 @@ /** * @see javax.servlet.ServletRequest#getLocalAddr() */ + @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalAddr() { return null; @@ -432,6 +475,7 @@ /** * @see javax.servlet.ServletRequest#getRemoteHost() */ + @Override public String getRemoteHost() { return null; } @@ -439,18 +483,21 @@ /** * @see javax.servlet.ServletRequest#setAttribute(String, Object) */ + @Override public void setAttribute(String arg0, Object arg1) { } /** * @see javax.servlet.ServletRequest#removeAttribute(String) */ + @Override public void removeAttribute(String arg0) { } /** * @see javax.servlet.ServletRequest#getLocale() */ + @Override public Locale getLocale() { return null; } @@ -458,6 +505,7 @@ /** * @see javax.servlet.ServletRequest#getLocales() */ + @Override public Enumeration getLocales() { return null; } @@ -465,6 +513,7 @@ /** * @see javax.servlet.ServletRequest#isSecure() */ + @Override public boolean isSecure() { return false; } @@ -472,6 +521,7 @@ /** * @see javax.servlet.ServletRequest#getRequestDispatcher(String) */ + @Override public RequestDispatcher getRequestDispatcher(String arg0) { return null; } @@ -480,6 +530,7 @@ * @see javax.servlet.ServletRequest#getRealPath(String) * @deprecated */ + @Override @Deprecated public String getRealPath(String arg0) { return null; diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/MultipartStreamTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/MultipartStreamTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/MultipartStreamTest.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/MultipartStreamTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -25,8 +25,6 @@ /** * Unit tests {@link org.apache.commons.fileupload.MultipartStream}. - * - * @version $Id$ */ public class MultipartStreamTest { @@ -48,7 +46,6 @@ assertNotNull(ms); } - @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testSmallBuffer() throws Exception { final String strData = "foobar"; diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/ParameterParserTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/ParameterParserTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/ParameterParserTest.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/ParameterParserTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -25,8 +25,6 @@ /** * Unit tests for {@link ParameterParser}. - * - * @version $Id$ */ public class ParameterParserTest { diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/portlet/MockPortletActionRequest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/portlet/MockPortletActionRequest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/portlet/MockPortletActionRequest.java 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/portlet/MockPortletActionRequest.java 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,271 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload.portlet; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Locale; +import java.util.Map; + +import javax.portlet.ActionRequest; +import javax.portlet.PortalContext; +import javax.portlet.PortletMode; +import javax.portlet.PortletPreferences; +import javax.portlet.PortletSession; +import javax.portlet.WindowState; + +import org.apache.commons.fileupload.FileUploadBase; + +/** + * Mock class for tests. Implements an {@link ActionRequest}. + * + * @see PortletFileUploadTest + * @since 1.4 + */ +@SuppressWarnings("rawtypes") // because of the portlet ActionRequest API does not use generics +public class MockPortletActionRequest implements ActionRequest { + + private final Hashtable attributes = new Hashtable(); + + private final Map parameters = new HashMap(); + + private String characterEncoding; + private final int length; + private final String contentType; + private final InputStream requestData; + + public MockPortletActionRequest(final byte[] requestData, final String contentType) { + this(new ByteArrayInputStream(requestData), requestData.length, contentType); + } + + public MockPortletActionRequest(ByteArrayInputStream byteArrayInputStream, int requestLength, String contentType) { + this.requestData = byteArrayInputStream; + length = requestLength; + this.contentType = contentType; + attributes.put(FileUploadBase.CONTENT_TYPE, contentType); + } + + @Override + public Object getAttribute(String key) { + return attributes.get(key); + } + + @Override + public Enumeration getAttributeNames() { + return attributes.keys(); + } + + @Override + public String getAuthType() { + return null; + } + + @Override + public String getContextPath() { + return null; + } + + @Override + public Locale getLocale() { + return Locale.getDefault(); + } + + @Override + public Enumeration getLocales() { + return Collections.enumeration(Arrays.asList(Locale.getAvailableLocales())); + } + + @Override + public String getParameter(String key) { + return parameters.get(key); + } + + @Override + public Map getParameterMap() { + return Collections.unmodifiableMap(parameters); + } + + @Override + public Enumeration getParameterNames() { + return Collections.enumeration(parameters.keySet()); + } + + @Override + public String[] getParameterValues(String arg0) { + return null; + } + + @Override + public PortalContext getPortalContext() { + return null; + } + + @Override + public PortletMode getPortletMode() { + return null; + } + + @Override + public PortletSession getPortletSession() { + return null; + } + + @Override + public PortletSession getPortletSession(boolean arg0) { + return null; + } + + @Override + public PortletPreferences getPreferences() { + return null; + } + + @Override + public Enumeration getProperties(String arg0) { + return null; + } + + @Override + public String getProperty(String arg0) { + return null; + } + + @Override + public Enumeration getPropertyNames() { + return null; + } + + @Override + public String getRemoteUser() { + return null; + } + + @Override + public String getRequestedSessionId() { + return null; + } + + @Override + public String getResponseContentType() { + return null; + } + + @Override + public Enumeration getResponseContentTypes() { + return null; + } + + @Override + public String getScheme() { + return null; + } + + @Override + public String getServerName() { + return null; + } + + @Override + public int getServerPort() { + return 0; + } + + @Override + public Principal getUserPrincipal() { + return null; + } + + @Override + public WindowState getWindowState() { + return null; + } + + @Override + public boolean isPortletModeAllowed(PortletMode arg0) { + return false; + } + + @Override + public boolean isRequestedSessionIdValid() { + return false; + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public boolean isUserInRole(String arg0) { + return false; + } + + @Override + public boolean isWindowStateAllowed(WindowState arg0) { + return false; + } + + @Override + public void removeAttribute(String key) { + attributes.remove(key); + } + + @Override + public void setAttribute(String key, Object value) { + attributes.put(key, value); + } + + @Override + public String getCharacterEncoding() { + return characterEncoding; + } + + @Override + public int getContentLength() { + return length; + } + + @Override + public String getContentType() { + return contentType; + } + + @Override + public InputStream getPortletInputStream() throws IOException { + return requestData; + } + + @Override + public BufferedReader getReader() throws UnsupportedEncodingException, IOException { + return null; + } + + @Override + public void setCharacterEncoding(String characterEncoding) throws UnsupportedEncodingException { + this.characterEncoding = characterEncoding; + } + +} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/portlet/PortletFileUploadTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/portlet/PortletFileUploadTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/portlet/PortletFileUploadTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/portlet/PortletFileUploadTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload.portlet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Map; + +import javax.portlet.ActionRequest; + +import org.apache.commons.fileupload.Constants; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileUploadTest; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.junit.Before; +import org.junit.Test; + +/** + * Test for {@link PortletFileUpload}. + * + * @see FileUploadTest + * @since 1.4 + */ +public class PortletFileUploadTest { + + private PortletFileUpload upload; + + @Before + public void setUp() { + upload = new PortletFileUpload(new DiskFileItemFactory()); + } + + @Test + public void parseParameterMap() + throws Exception { + String text = "-----1234\r\n" + + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + + "Content-Type: text/whatever\r\n" + + "\r\n" + + "This is the content of the file\n" + + "\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"field\"\r\n" + + "\r\n" + + "fieldValue\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value1\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value2\r\n" + + "-----1234--\r\n"; + byte[] bytes = text.getBytes("US-ASCII"); + ActionRequest request = new MockPortletActionRequest(bytes, Constants.CONTENT_TYPE); + + Map> mappedParameters = upload.parseParameterMap(request); + assertTrue(mappedParameters.containsKey("file")); + assertEquals(1, mappedParameters.get("file").size()); + + assertTrue(mappedParameters.containsKey("field")); + assertEquals(1, mappedParameters.get("field").size()); + + assertTrue(mappedParameters.containsKey("multi")); + assertEquals(2, mappedParameters.get("multi").size()); + } + +} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -28,11 +28,9 @@ import org.junit.Test; /** - * Tests the progress listener. - * - * @version $Id$ + * Tests the {@link ProgressListener}. */ -public class ProgressListenerTest extends FileUploadTestCase { +public class ProgressListenerTest { private class ProgressListenerImpl implements ProgressListener { @@ -49,6 +47,7 @@ expectedItems = pItems; } + @Override public void update(long pBytesRead, long pContentLength, int pItems) { assertTrue(pBytesRead >= 0 && pBytesRead <= expectedContentLength); assertTrue(pContentLength == -1 || pContentLength == expectedContentLength); @@ -87,9 +86,9 @@ baos.write("-----1234--\r\n".getBytes("US-ASCII")); byte[] contents = baos.toByteArray(); - MockHttpServletRequest request = new MockHttpServletRequest(contents, "multipart/form-data; boundary=---1234"); + MockHttpServletRequest request = new MockHttpServletRequest(contents, Constants.CONTENT_TYPE); runTest(NUM_ITEMS, contents.length, request); - request = new MockHttpServletRequest(contents, "multipart/form-data; boundary=---1234"){ + request = new MockHttpServletRequest(contents, Constants.CONTENT_TYPE){ @Override public int getContentLength() { return -1; @@ -120,6 +119,7 @@ } } assertEquals(-1, istream.read()); + istream.close(); } assertTrue(!iter.hasNext()); listener.checkFinished(); diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/servlet/ServletFileUploadTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/servlet/ServletFileUploadTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/servlet/ServletFileUploadTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/servlet/ServletFileUploadTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload.servlet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload.Constants; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.MockHttpServletRequest; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.junit.Test; + +/** + * Test for {@link ServletFileUpload}. + * + * @see FileUploadTest + * @since 1.4 + */ +public class ServletFileUploadTest { + + /** + * Test case for + */ + @Test + public void parseParameterMap() + throws Exception { + String text = "-----1234\r\n" + + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + + "Content-Type: text/whatever\r\n" + + "\r\n" + + "This is the content of the file\n" + + "\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"field\"\r\n" + + "\r\n" + + "fieldValue\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value1\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value2\r\n" + + "-----1234--\r\n"; + byte[] bytes = text.getBytes("US-ASCII"); + HttpServletRequest request = new MockHttpServletRequest(bytes, Constants.CONTENT_TYPE); + + ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); + Map> mappedParameters = upload.parseParameterMap(request); + assertTrue(mappedParameters.containsKey("file")); + assertEquals(1, mappedParameters.get("file").size()); + + assertTrue(mappedParameters.containsKey("field")); + assertEquals(1, mappedParameters.get("field").size()); + + assertTrue(mappedParameters.containsKey("multi")); + assertEquals(2, mappedParameters.get("multi").size()); + } + + + @Test + public void parseImpliedUtf8() + throws Exception { + // utf8 encoded form-data without explicit content-type encoding + String text = "-----1234\r\n" + + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + + "\r\n" + + "Thís ís the coñteñt of the fíle\n" + + "\r\n" + + "-----1234--\r\n"; + + byte[] bytes = text.getBytes("UTF-8"); + HttpServletRequest request = new MockHttpServletRequest(bytes, Constants.CONTENT_TYPE); + + DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(); + fileItemFactory.setDefaultCharset("UTF-8"); + ServletFileUpload upload = new ServletFileUpload(fileItemFactory); + List fileItems = upload.parseRequest(request); + FileItem fileItem = fileItems.get(0); + assertTrue(fileItem.getString(), fileItem.getString().contains("coñteñt")); + } +} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/ServletFileUploadTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/ServletFileUploadTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/ServletFileUploadTest.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/ServletFileUploadTest.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,411 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.fileupload; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.junit.Test; - -/** - * Unit tests {@link org.apache.commons.fileupload.DiskFileUpload}. - * - * @version $Id$ - */ -@SuppressWarnings({"deprecation", "javadoc"}) // unit tests for deprecated class -public class ServletFileUploadTest extends FileUploadTestCase { - - @Test - public void testWithInvalidRequest() { - FileUploadBase fu = null; - - fu = new DiskFileUpload(); - - HttpServletRequest req = HttpServletRequestFactory.createInvalidHttpServletRequest(); - - - try { - fu.parseRequest(req); - fail("testWithInvalidRequest: expected exception was not thrown"); - } catch (FileUploadException expected) { - // this exception is expected - } - } - - @Test - public void testWithNullContentType() { - FileUploadBase fu = new DiskFileUpload(); - - HttpServletRequest req = HttpServletRequestFactory.createHttpServletRequestWithNullContentType(); - - try { - fu.parseRequest(req); - fail("testWithNullContentType: expected exception was not thrown"); - } catch (DiskFileUpload.InvalidContentTypeException expected) { - // this exception is expected - } catch (FileUploadException unexpected) { - fail("testWithNullContentType: unexpected exception was thrown"); - } - } - - @Test - public void testFileUpload() - throws IOException, FileUploadException { - List fileItems = parseUpload("-----1234\r\n" + - "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + - "Content-Type: text/whatever\r\n" + - "\r\n" + - "This is the content of the file\n" + - "\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"field\"\r\n" + - "\r\n" + - "fieldValue\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"multi\"\r\n" + - "\r\n" + - "value1\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"multi\"\r\n" + - "\r\n" + - "value2\r\n" + - "-----1234--\r\n"); - assertEquals(4, fileItems.size()); - - FileItem file = fileItems.get(0); - assertEquals("file", file.getFieldName()); - assertFalse(file.isFormField()); - assertEquals("This is the content of the file\n", file.getString()); - assertEquals("text/whatever", file.getContentType()); - assertEquals("foo.tab", file.getName()); - - FileItem field = fileItems.get(1); - assertEquals("field", field.getFieldName()); - assertTrue(field.isFormField()); - assertEquals("fieldValue", field.getString()); - - FileItem multi0 = fileItems.get(2); - assertEquals("multi", multi0.getFieldName()); - assertTrue(multi0.isFormField()); - assertEquals("value1", multi0.getString()); - - FileItem multi1 = fileItems.get(3); - assertEquals("multi", multi1.getFieldName()); - assertTrue(multi1.isFormField()); - assertEquals("value2", multi1.getString()); - } - - @Test - public void testFilenameCaseSensitivity() - throws IOException, FileUploadException { - List fileItems = parseUpload("-----1234\r\n" + - "Content-Disposition: form-data; name=\"FiLe\"; filename=\"FOO.tab\"\r\n" + - "Content-Type: text/whatever\r\n" + - "\r\n" + - "This is the content of the file\n" + - "\r\n" + - "-----1234--\r\n"); - assertEquals(1, fileItems.size()); - - FileItem file = fileItems.get(0); - assertEquals("FiLe", file.getFieldName()); - assertEquals("FOO.tab", file.getName()); - } - - /** - * This is what the browser does if you submit the form without choosing a file. - */ - @Test - public void testEmptyFile() - throws UnsupportedEncodingException, FileUploadException { - List fileItems = parseUpload ("-----1234\r\n" + - "Content-Disposition: form-data; name=\"file\"; filename=\"\"\r\n" + - "\r\n" + - "\r\n" + - "-----1234--\r\n"); - assertEquals(1, fileItems.size()); - - FileItem file = fileItems.get(0); - assertFalse(file.isFormField()); - assertEquals("", file.getString()); - assertEquals("", file.getName()); - } - - /** - * Internet Explorer 5 for the Mac has a bug where the carriage - * return is missing on any boundary line immediately preceding - * an input with type=image. (type=submit does not have the bug.) - */ - @Test - public void testIE5MacBug() - throws UnsupportedEncodingException, FileUploadException { - List fileItems = parseUpload("-----1234\r\n" + - "Content-Disposition: form-data; name=\"field1\"\r\n" + - "\r\n" + - "fieldValue\r\n" + - "-----1234\n" + // NOTE \r missing - "Content-Disposition: form-data; name=\"submitName.x\"\r\n" + - "\r\n" + - "42\r\n" + - "-----1234\n" + // NOTE \r missing - "Content-Disposition: form-data; name=\"submitName.y\"\r\n" + - "\r\n" + - "21\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"field2\"\r\n" + - "\r\n" + - "fieldValue2\r\n" + - "-----1234--\r\n"); - - assertEquals(4, fileItems.size()); - - FileItem field1 = fileItems.get(0); - assertEquals("field1", field1.getFieldName()); - assertTrue(field1.isFormField()); - assertEquals("fieldValue", field1.getString()); - - FileItem submitX = fileItems.get(1); - assertEquals("submitName.x", submitX.getFieldName()); - assertTrue(submitX.isFormField()); - assertEquals("42", submitX.getString()); - - FileItem submitY = fileItems.get(2); - assertEquals("submitName.y", submitY.getFieldName()); - assertTrue(submitY.isFormField()); - assertEquals("21", submitY.getString()); - - FileItem field2 = fileItems.get(3); - assertEquals("field2", field2.getFieldName()); - assertTrue(field2.isFormField()); - assertEquals("fieldValue2", field2.getString()); - } - - /** - * Test for FILEUPLOAD-62 - */ - @Test - public void testFILEUPLOAD62() throws Exception { - final String contentType = "multipart/form-data; boundary=AaB03x"; - final String request = - "--AaB03x\r\n" + - "content-disposition: form-data; name=\"field1\"\r\n" + - "\r\n" + - "Joe Blow\r\n" + - "--AaB03x\r\n" + - "content-disposition: form-data; name=\"pics\"\r\n" + - "Content-type: multipart/mixed; boundary=BbC04y\r\n" + - "\r\n" + - "--BbC04y\r\n" + - "Content-disposition: attachment; filename=\"file1.txt\"\r\n" + - "Content-Type: text/plain\r\n" + - "\r\n" + - "... contents of file1.txt ...\r\n" + - "--BbC04y\r\n" + - "Content-disposition: attachment; filename=\"file2.gif\"\r\n" + - "Content-type: image/gif\r\n" + - "Content-Transfer-Encoding: binary\r\n" + - "\r\n" + - "...contents of file2.gif...\r\n" + - "--BbC04y--\r\n" + - "--AaB03x--"; - List fileItems = parseUpload(request.getBytes("US-ASCII"), contentType); - assertEquals(3, fileItems.size()); - FileItem item0 = fileItems.get(0); - assertEquals("field1", item0.getFieldName()); - assertNull(item0.getName()); - assertEquals("Joe Blow", new String(item0.get())); - FileItem item1 = fileItems.get(1); - assertEquals("pics", item1.getFieldName()); - assertEquals("file1.txt", item1.getName()); - assertEquals("... contents of file1.txt ...", new String(item1.get())); - FileItem item2 = fileItems.get(2); - assertEquals("pics", item2.getFieldName()); - assertEquals("file2.gif", item2.getName()); - assertEquals("...contents of file2.gif...", new String(item2.get())); - } - - /** - * Test for FILEUPLOAD-111 - */ - @Test - public void testFoldedHeaders() - throws IOException, FileUploadException { - List fileItems = parseUpload("-----1234\r\n" + - "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + - "Content-Type: text/whatever\r\n" + - "\r\n" + - "This is the content of the file\n" + - "\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; \r\n" + - "\tname=\"field\"\r\n" + - "\r\n" + - "fieldValue\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data;\r\n" + - " name=\"multi\"\r\n" + - "\r\n" + - "value1\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"multi\"\r\n" + - "\r\n" + - "value2\r\n" + - "-----1234--\r\n"); - assertEquals(4, fileItems.size()); - - FileItem file = fileItems.get(0); - assertEquals("file", file.getFieldName()); - assertFalse(file.isFormField()); - assertEquals("This is the content of the file\n", file.getString()); - assertEquals("text/whatever", file.getContentType()); - assertEquals("foo.tab", file.getName()); - - FileItem field = fileItems.get(1); - assertEquals("field", field.getFieldName()); - assertTrue(field.isFormField()); - assertEquals("fieldValue", field.getString()); - - FileItem multi0 = fileItems.get(2); - assertEquals("multi", multi0.getFieldName()); - assertTrue(multi0.isFormField()); - assertEquals("value1", multi0.getString()); - - FileItem multi1 = fileItems.get(3); - assertEquals("multi", multi1.getFieldName()); - assertTrue(multi1.isFormField()); - assertEquals("value2", multi1.getString()); - } - - /** - * Test case for - */ - @Test - public void testFileUpload130() - throws Exception { - final String[] headerNames = new String[] - { - "SomeHeader", "OtherHeader", "YetAnotherHeader", "WhatAHeader" - }; - final String[] headerValues = new String[] - { - "present", "Is there", "Here", "Is That" - }; - List fileItems = parseUpload("-----1234\r\n" + - "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + - "Content-Type: text/whatever\r\n" + - headerNames[0] + ": " + headerValues[0] + "\r\n" + - "\r\n" + - "This is the content of the file\n" + - "\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; \r\n" + - "\tname=\"field\"\r\n" + - headerNames[1] + ": " + headerValues[1] + "\r\n" + - "\r\n" + - "fieldValue\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data;\r\n" + - " name=\"multi\"\r\n" + - headerNames[2] + ": " + headerValues[2] + "\r\n" + - "\r\n" + - "value1\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"multi\"\r\n" + - headerNames[3] + ": " + headerValues[3] + "\r\n" + - "\r\n" + - "value2\r\n" + - "-----1234--\r\n"); - assertEquals(4, fileItems.size()); - - FileItem file = fileItems.get(0); - assertHeaders(headerNames, headerValues, file, 0); - - FileItem field = fileItems.get(1); - assertHeaders(headerNames, headerValues, field, 1); - - FileItem multi0 = fileItems.get(2); - assertHeaders(headerNames, headerValues, multi0, 2); - - FileItem multi1 = fileItems.get(3); - assertHeaders(headerNames, headerValues, multi1, 3); - } - - /** - * Test case for - */ - @Test - public void parseParameterMap() - throws Exception { - String text = "-----1234\r\n" + - "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + - "Content-Type: text/whatever\r\n" + - "\r\n" + - "This is the content of the file\n" + - "\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"field\"\r\n" + - "\r\n" + - "fieldValue\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"multi\"\r\n" + - "\r\n" + - "value1\r\n" + - "-----1234\r\n" + - "Content-Disposition: form-data; name=\"multi\"\r\n" + - "\r\n" + - "value2\r\n" + - "-----1234--\r\n"; - byte[] bytes = text.getBytes("US-ASCII"); - ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); - HttpServletRequest request = new MockHttpServletRequest(bytes, CONTENT_TYPE); - - Map> mappedParameters = upload.parseParameterMap(request); - assertTrue(mappedParameters.containsKey("file")); - assertEquals(1, mappedParameters.get("file").size()); - - assertTrue(mappedParameters.containsKey("field")); - assertEquals(1, mappedParameters.get("field").size()); - - assertTrue(mappedParameters.containsKey("multi")); - assertEquals(2, mappedParameters.get("multi").size()); - } - - private void assertHeaders(String[] pHeaderNames, String[] pHeaderValues, - FileItem pItem, int pIndex) { - for (int i = 0; i < pHeaderNames.length; i++) { - final String value = pItem.getHeaders().getHeader(pHeaderNames[i]); - if (i == pIndex) { - assertEquals(pHeaderValues[i], value); - } else { - assertNull(value); - } - } - } - -} diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/SizesTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/SizesTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/SizesTest.java 2017-06-09 22:23:24.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/SizesTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -38,10 +38,8 @@ /** * Unit test for items with varying sizes. - * - * @version $Id$ */ -public class SizesTest extends FileUploadTestCase { +public class SizesTest { /** * Runs a test with varying file sizes. @@ -67,7 +65,8 @@ } baos.write("-----1234--\r\n".getBytes("US-ASCII")); - List fileItems = parseUpload(baos.toByteArray()); + List fileItems = + Util.parseUpload(new ServletFileUpload(new DiskFileItemFactory()), baos.toByteArray()); Iterator fileIter = fileItems.iterator(); add = 16; num = 0; @@ -102,7 +101,8 @@ ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); upload.setFileSizeMax(-1); - HttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + HttpServletRequest req = new MockHttpServletRequest( + request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); List fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); FileItem item = fileItems.get(0); @@ -110,7 +110,7 @@ upload = new ServletFileUpload(new DiskFileItemFactory()); upload.setFileSizeMax(40); - req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); item = fileItems.get(0); @@ -118,7 +118,7 @@ upload = new ServletFileUpload(new DiskFileItemFactory()); upload.setFileSizeMax(30); - req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); try { upload.parseRequest(req); fail("Expected exception."); @@ -144,7 +144,8 @@ ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); upload.setFileSizeMax(-1); - HttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + HttpServletRequest req = new MockHttpServletRequest( + request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); List fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); FileItem item = fileItems.get(0); @@ -152,7 +153,7 @@ upload = new ServletFileUpload(new DiskFileItemFactory()); upload.setFileSizeMax(40); - req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); item = fileItems.get(0); @@ -161,7 +162,7 @@ // provided Content-Length is larger than the FileSizeMax -> handled by ctor upload = new ServletFileUpload(new DiskFileItemFactory()); upload.setFileSizeMax(5); - req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); try { upload.parseRequest(req); fail("Expected exception."); @@ -172,7 +173,7 @@ // provided Content-Length is wrong, actual content is larger -> handled by LimitedInputStream upload = new ServletFileUpload(new DiskFileItemFactory()); upload.setFileSizeMax(15); - req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); try { upload.parseRequest(req); fail("Expected exception."); @@ -206,14 +207,14 @@ upload.setFileSizeMax(-1); upload.setSizeMax(200); - MockHttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + MockHttpServletRequest req = new MockHttpServletRequest( + request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); try { upload.parseRequest(req); fail("Expected exception."); } catch (FileUploadBase.SizeLimitExceededException e) { assertEquals(200, e.getPermittedSize()); } - } @Test @@ -243,7 +244,8 @@ // set the read limit to 10 to simulate a "real" stream // otherwise the buffer would be immediately filled - MockHttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE); + MockHttpServletRequest req = new MockHttpServletRequest( + request.getBytes("US-ASCII"), Constants.CONTENT_TYPE); req.setContentLength(-1); req.setReadLimit(10); @@ -255,12 +257,10 @@ assertEquals("file1", item.getFieldName()); assertEquals("foo1.tab", item.getName()); - try { + { InputStream stream = item.openStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Streams.copy(stream, baos, true); - } catch (FileUploadIOException e) { - fail(e.getMessage()); } // the second item is over the size max, thus we expect an error @@ -281,7 +281,6 @@ } catch (FileUploadIOException e) { // expected } - } } diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/StreamingTest.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/StreamingTest.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/StreamingTest.java 2017-05-30 12:22:29.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/StreamingTest.java 2018-12-24 06:43:43.000000000 +0000 @@ -35,8 +35,6 @@ /** * Unit test for items with varying sizes. - * - * @version $Id$ */ public class StreamingTest extends TestCase { diff -Nru libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/Util.java libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/Util.java --- libcommons-fileupload-java-1.3.3/src/test/java/org/apache/commons/fileupload/Util.java 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/src/test/java/org/apache/commons/fileupload/Util.java 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.portlet.PortletFileUpload; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.fileupload.servlet.ServletRequestContext; + +/** + * Test utility methods. + * + * @since 1.4 + */ +public class Util { + + public static List parseUpload(FileUpload upload, byte[] bytes) throws FileUploadException { + return parseUpload(upload, bytes, Constants.CONTENT_TYPE); + } + + public static List parseUpload(FileUpload upload, byte[] bytes, String contentType) throws FileUploadException { + final HttpServletRequest request = new MockHttpServletRequest(bytes, contentType); + List fileItems = upload.parseRequest(new ServletRequestContext(request)); + return fileItems; + } + + public static List parseUpload(FileUpload upload, String content) + throws UnsupportedEncodingException, FileUploadException { + byte[] bytes = content.getBytes("US-ASCII"); + return parseUpload(upload, bytes, Constants.CONTENT_TYPE); + } + + /** + * Return a list of {@link FileUpload} implementations for parameterized tests. + * @return a list of {@link FileUpload} implementations + */ + public static List fileUploadImplementations() { + return Arrays.asList( + new ServletFileUpload(new DiskFileItemFactory()), + new PortletFileUpload(new DiskFileItemFactory())); + } +} diff -Nru libcommons-fileupload-java-1.3.3/.travis.yml libcommons-fileupload-java-1.4/.travis.yml --- libcommons-fileupload-java-1.3.3/.travis.yml 1970-01-01 00:00:00.000000000 +0000 +++ libcommons-fileupload-java-1.4/.travis.yml 2018-12-24 06:43:43.000000000 +0000 @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +language: java +sudo: false + +jdk: + - openjdk7 + - oraclejdk8 + - oraclejdk9 + +after_success: + - mvn clean test jacoco:report coveralls:report -Ptravis-jacoco \ No newline at end of file