Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-880

DataSourceResourceLoader corrupts UTF-8 encoded characters in template

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.x
    • 2.0
    • None
    • None
    • Oracle12c and HSQLDB 2.3.4, JDK 1.8
    • Patch

    Description

      A long-withstanding bug in the DataSourceResourceLoader corrupts UTF-8 templates retrieved from the database. The Unit Test suite for this resource loader has deficiencies that hide the bug.

      The cause of the problem is this:

            InputStream rawStream = rs.getAsciiStream(templateColumn);
      
      The resolution of the problem is simply:
            Reader r = rs.getCharacterStream(templateColumn);
            InputStream rawStream = null;
                 try {
                      rawStream = IOUtils.toInputStream(IOUtils.toString(r), encoding);
                      } catch (IOException ioe) {}
      

      Once done, the test failure vanishes:
      org.junit.ComparisonFailure: Unicode test failed.
      Expected :The Euro Currency Symbol € is a two-byte UTF-8 encoded character.
      Actual :The Euro Currency Symbol ? is a two-byte UTF-8 encoded character.

      The bug was verified and the fix was tested against Oracle12c and HSQLDB 2.3.4 using a CLOB column to store the template data.

      The Unit Tests for this resource loader need attention.

      Please see VELOCITY-599 ; long standing problem, which has been erroneously marked as resolved but has been in the codebase for a long time.

      Attachments

        1. project.tar.gz
          7.90 MB
          James R Doyle
        2. velocity-880.patch
          6 kB
          James R Doyle

        Issue Links

          Activity

            People

              cbrisson Claude Brisson
              jrdmedford James R Doyle
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 24h
                  24h
                  Remaining:
                  Remaining Estimate - 24h
                  24h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified