Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-150

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

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1
    • 2.2
    • None
    • None
    • Operating System: All
      Platform: PC

    • 38569

    Description

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

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

      Output:
      test & ä ö

      Expected output:
      test & ä ö

      Attachments

        Activity

          trejkaz 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.

          trejkaz 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.
          bayard 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 &.

          bayard 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 &.
          bayard 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.

          bayard 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

            Unassigned Unassigned
            duy.dao@azonline.ch Duy Dao
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: