Commons Lang
  1. Commons Lang
  2. LANG-150

[lang] StringEscapeUtils.unescapeHtml skips first entity after standalone ampersand

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: PC

      Description

      StringEscapeUtils.unescapeHtml skips the first entity after a standalone ampersand.

      Code:
      System.out.println(
      StringEscapeUtils.unescapeHtml("test & ä ö")
      );

      Output:
      test & ä ö

      Expected output:
      test & ä ö

        Activity

        Hide
        Trejkaz added a comment -

        Created an attachment (id=17838)
        Patch to work around this issue

        This patch works around spaces being between the '&' and the ';'. To be more
        correct, it should probably ensure that all characters between the '&' and ';'
        are valid entity characters, but in most cases the offending character is a
        space.

        Show
        Trejkaz added a comment - Created an attachment (id=17838) Patch to work around this issue This patch works around spaces being between the '&' and the ';'. To be more correct, it should probably ensure that all characters between the '&' and ';' are valid entity characters, but in most cases the offending character is a space.
        Hide
        Henri Yandell added a comment -

        Recreated issue with unit test. The proposed solution is too simple - we need to
        be able to handle all situations, not just times when there is a space after the &.

        Show
        Henri Yandell added a comment - Recreated issue with unit test. The proposed solution is too simple - we need to be able to handle all situations, not just times when there is a space after the &.
        Hide
        Henri Yandell added a comment -

        Fixed by checking whether an & is closer than the subsequent ;. If so, then skip
        onwards. Also a problem in unescapeXml.

        svn ci -m "Fixing issue #38569"
        Sending src/java/org/apache/commons/lang/Entities.java
        Sending src/test/org/apache/commons/lang/StringEscapeUtilsTest.java
        Transmitting file data ..
        Committed revision 394875.

        Show
        Henri Yandell added a comment - Fixed by checking whether an & is closer than the subsequent ;. If so, then skip onwards. Also a problem in unescapeXml. svn ci -m "Fixing issue #38569" Sending src/java/org/apache/commons/lang/Entities.java Sending src/test/org/apache/commons/lang/StringEscapeUtilsTest.java Transmitting file data .. Committed revision 394875.

          People

          • Assignee:
            Unassigned
            Reporter:
            Duy Dao
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development