jaxb
  1. jaxb
  2. JAXB-959

The default UTF CharacterEscapeHandler (MinimumEscapeHandler) eats carriage returns

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.2.6
    • Fix Version/s: None
    • Component/s: runtime
    • Labels:
      None

      Description

      For some reason the default UTF CharacterEscapeHandler (MinimumEscapeHandler) eats carriage returns ("\r"), i.e. it doesn't write them to the output. NioEscapeHandler, an alternate CharacterEscapeHandler included in JAXB, doesn't ignore them. Here's the relevant code:

          public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
              // avoid calling the Writerwrite method too much by assuming
              // that the escaping occurs rarely.
              // profiling revealed that this is faster than the naive code.
              int limit = start+length;
              for (int i = start; i < limit; i++) {
                  char c = ch[i];
                      if(c == '&' || c == '<' || c == '>' || c == '\r' || (c == '\"' && isAttVal) ) {
                      if(i!=start)
                          out.write(ch,start,i-start);
                      start = i+1;
                      switch (ch[i]) {
                          case '&':
                              out.write("&amp;");
                              break;
                          case '<':
                              out.write("&lt;");
                              break;
                          case '>':
                              out.write("&gt;");
                              break;
                          case '\"':
                              out.write("&quot;");
                              break;
                      }
                  }
              }
              
              if( start!=limit )
                  out.write(ch,start,limit-start);
          }

        Activity

        Hide
        gredler added a comment -

        Possibly relevant past issue (though I can't find a record in SVN of how it was addressed in the code): JAXB-449

        Show
        gredler added a comment - Possibly relevant past issue (though I can't find a record in SVN of how it was addressed in the code): JAXB-449

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            gredler
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: