Skip to content

Commit 1aad64a

Browse files
Remove sensitivity to encoding hashtable ordering by accepting only the first mapping seen for each key. Relies on encodings.properties putting the preferred java name first (equivalent to its current rule that when multipel mime names are given, the first is preferred).
1 parent 289dd5f commit 1aad64a

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

serializer/src/main/java/org/apache/xml/serializer/Encodings.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
/**
3737
* Provides information about encodings. Depends on the Java runtime
3838
* to provides writers for the different encodings.
39+
*
40+
* NOTE: When a Java or MIME names appears more than once in the
41+
* encodings.properties table, priority is given to the first instance
42+
* seen. For example, MIME name ISO-8859-1 will be mapped to Java name
43+
* ISO8859-1, even though the file includes synonyms such as ISO8859_1
44+
* and 8859-1.
3945
* <p>
4046
* This class is not a public API. It is only public because it
4147
* is used outside of this package.
@@ -369,9 +375,9 @@ private static EncodingInfo[] loadEncodingInfo()
369375
mimeName = st.nextToken();
370376
EncodingInfo ei = new EncodingInfo(mimeName, javaName, highChar);
371377
encodingInfo_list.add(ei);
372-
_encodingTableKeyMime.put(mimeName.toUpperCase(), ei);
378+
_encodingTableKeyMime.putIfAbsent(mimeName.toUpperCase(), ei);
373379
if (first)
374-
_encodingTableKeyJava.put(javaName.toUpperCase(), ei);
380+
_encodingTableKeyJava.putIfAbsent(javaName.toUpperCase(), ei);
375381
}
376382
}
377383
}

serializer/src/main/resources/org/apache/xml/serializer/Encodings.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
# Higher values above this char might be in the encoding, although in the
3838
# case of this particular encoding there are no higher chars.
3939
#
40+
# NOTE: When a Java or MIME names appears more than once in this
41+
# table, priority is given to the first instance seen. For example,
42+
# MIME name ISO-8859-1 will be mapped to Java name ISO8859-1.
4043
#
4144
# <JAVA name encoding>, <PREFERRED name MIME>
4245
#

0 commit comments

Comments
 (0)