Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-1761

JcrPropertyResource sets incorrect content length for strings containing non-ascii character

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • JCR Resource 2.0.6
    • JCR Resource 2.0.8
    • JCR
    • None

    Description

      JcrPropertyResource sets the content length of the property in its metadata. To do so, it uses javax.jcr.Property#getLength() to determine the content length.

      The documentation for javax.jcr.Property#getLength() states "[...] Returns the length in bytes if the value is a PropertyType.BINARY, otherwise it returns the number of characters needed to display the value in its string form. [...]".

      The documentation in ResourceMetadata is not explicit, but from its usage in StreamRendererServlet I conclude that ResourceMetadata.getContentLength() is intended for use in the Content-Length HTTP header. If my assumptions are correct, the content length indicates the number of bytes in the string, while javax.jcr.Property#getLength() returns the number of characters.

      The effect of this can be observed by the following steps:

      • create a string property "/utf8string" with value "Bär"
      • access this property using a browser (e.g. http://localhost:8888/utf8string), so that the property gets rendered by the StreamRendererServlet
        => the string is rendered incorrectly (due to a missing Content-Type header)
        => the string is cut off (due to the incorrectly set Content-Length header)

      Attachments

        1. SLING-1761.patch
          6 kB
          Julian Sedding
        2. SLING-1761-tests.patch
          6 kB
          Julian Sedding

        Activity

          People

            cziegeler Carsten Ziegeler
            jsedding Julian Sedding
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: