Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-69122

FileUtil.encodeSafeFileName() can be lossy, if the original file name includes reserved characters

    Details

      Description

      FileUtil.encodeSafeFileName() and FileUtil.decodeSafeFileName() are not exactly reversible.

      Consider the following groovy script

      originalFileName = "_CP_)"
      out.println("Original file name: " + originalFileName);
      encodedFileName = com.liferay.portal.kernel.util.FileUtil.encodeSafeFileName(originalFileName);
      out.println("Encoded file name: " + encodedFileName);
      decodedFileName = com.liferay.portal.kernel.util.FileUtil.decodeSafeFileName(encodedFileName);
      out.println("Decoded file name: " + decodedFileName);

      As encodeSafeFileName substitutes ')' by "_CP_", if the original filename included "_CP_", decodeSafeFileName() would substitute back "_CP_" by ')', and, thus, the original file name would not be preserved.

      It is unlikely, but possible.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              felix.zhang Felix Zhang
              Reporter:
              alberto.montero Alberto Montero
              Participants of an Issue:
              Recent user:
              Csaba Turcsan
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                4 years, 40 weeks, 4 days ago

                  Packages

                  Version Package
                  6.2.X EE
                  7.0.0 DXP FP9
                  7.0.0 DXP SP2
                  7.0.3 CE GA4
                  7.1.X
                  Master