< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToTextStream.java

Print this page

        

@@ -1,8 +1,7 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.

@@ -32,10 +31,11 @@
  * This class is not a public API.
  * It is only public because it is used in other packages.
  * This class converts SAX or SAX-like calls to a
  * serialized document for xsl:output method of "text".
  * @xsl.usage internal
+ * @LastModified: Sept 2018
  */
 public final class ToTextStream extends ToStream
 {
 
 

@@ -293,13 +293,23 @@
                 writer.write(m_lineSep, 0, m_lineSepLen);
                 // one input char processed
             } else if (m_encodingInfo.isInEncoding(c)) {
                 writer.write(c);
                 // one input char processed
-            } else if (Encodings.isHighUTF16Surrogate(c)) {
+            } else if (Encodings.isHighUTF16Surrogate(c) ||
+                       Encodings.isLowUTF16Surrogate(c)) {
                 final int codePoint = writeUTF16Surrogate(c, ch, i, end);
-                if (codePoint != 0) {
+                if (codePoint >= 0) {
+                    // move the index if the low surrogate is consumed
+                    // as writeUTF16Surrogate has written the pair
+                    if (Encodings.isHighUTF16Surrogate(c)) {
+                        i++;
+                    }
+
+                    // printing to the console is not appropriate, but will leave
+                    // it as is for compatibility.
+                    if (codePoint >0) {
                     // I think we can just emit the message,
                     // not crash and burn.
                     final String integralValue = Integer.toString(codePoint);
                     final String msg = Utils.messages.createMessage(
                         MsgKey.ER_ILLEGAL_CHARACTER,

@@ -307,13 +317,12 @@
 
                     //Older behavior was to throw the message,
                     //but newer gentler behavior is to write a message to System.err
                     //throw new SAXException(msg);
                     System.err.println(msg);
-
                 }
-                i++; // two input chars processed
+                }
             } else {
                 // Don't know what to do with this char, it is
                 // not in the encoding and not a high char in
                 // a surrogate pair, so write out as an entity ref
                 if (encoding != null) {
< prev index next >