Jump to content
  • Possible Bug With Style Element and Special Characters (like &)


    cutshaw
    Assigned User teodord
    CategoryBug report
    PriorityHigh
    ReproducibilityAlways
    ResolutionFixed
    SeverityMajor
    StatusClosed

    I may have found a bug with processing style elements and converting special characters. I have the following text field in a sub-report:

     

    $F{ListItem}

     

    ListItem contains '&' characters that are converted to "&" before the report is created. The conversion works fine, but it looks like Jasper reports computes whether or not the text field will fit inside the report element before the "&" is converted back to '&'. My text field gets truncated even though there should be plenty of space left in the report element.

     



    User Feedback

    Recommended Comments

     

    Hi,

     

    I don\'t see why you need to double encode the ampersand character if the value comes from a report field or report parameter and is not hard-coded in the JRXML itself.

    I think you should escape them with a simple & sequence.

     

    Thank you,

    Teodor

     

    Link to comment
    Share on other sites

    When I try the simple "&" sequence, I get an XML parsing error. For example, if the report field contains the string "C&DH", and I convert it to "C&DH", I get the following error:

     

    09:54:17,312 ERROR [sTDERR] [Fatal Error] :1:9: The reference to entity "DH" must end with the \';\' delimiter.

     

    But the double escape seems to work, except for the width issue.

     

    By the way, I\'m currently using version 1.2.1 of Jasper Reports.

    Link to comment
    Share on other sites

     

    Hi, Mark

     

    I think this is indeed a bug that has been around for sometime now.

     

    The correct procedure in your case would be to encode the ampersand only once.

    I have made some tests and I do get the error you mentioned, but it is an error that occurs when the report is displayed, not when it is filled.

    The problem is that we forgot to encode the XML content back when putting it in the generated document.

    This is why we get the error at view time, because the styled text XML is no longer properly encoded and parsing it again fails.

     

    In order to overcome this, you tried to double encode it and came across the second side-effect of the bug related to the text length.

     

    The fix is pretty easy, but needs careful testing.

    It also will have an impact on existing report templates that contain hardcoded styledtext, which would probably have to be revised and propertly encoded.

     

    We\'ll let you know how this goes.

     

    Thank you,

    Teodor

     

    Link to comment
    Share on other sites

     

    Hi,

     

    I made the fix in the JRStyledTextParser class and this is now available on SVN.

    The sample in /demo/samples/styledtext had to be adapted to remove double encoding.

     

    It would be great if you could test the latest version from SVN and see if it solves your problem.

     

    If everything goes OK, this will be part of the next release.

     

    Thank you,

    Teodor

     

    Link to comment
    Share on other sites

    I don\'t currently have the Jasper source code on my PC, so it would take me quite a bit of time to build a new jar file. But I would be happy to test the fix if you could email me the new jar file or provide a web link to it. I looked around the Jasper Forge site for the jar, but was unable to find it.

     

    By the way, I\'ve been able to get around the problem by widening my report element and using a smaller font, so the bug is not a critical problem for me right now.

    Link to comment
    Share on other sites

     

    Hi,

     

    Building the source files should be easy. You only need to get the latest from SVN using an SVN client and then build them with Ant from command line.

     

    I have attached the JAR.

     

    Thank you,

    Teodor

     

    Link to comment
    Share on other sites


×
×
  • Create New...