From 1aad64ae6f196b34a36e4971b50ff730c9b95d9c Mon Sep 17 00:00:00 2001 From: kubycsolutions Date: Fri, 26 Jan 2024 12:42:28 -0500 Subject: [PATCH] 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). --- .../main/java/org/apache/xml/serializer/Encodings.java | 10 ++++++++-- .../org/apache/xml/serializer/Encodings.properties | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/serializer/src/main/java/org/apache/xml/serializer/Encodings.java b/serializer/src/main/java/org/apache/xml/serializer/Encodings.java index 00dd8ea04..b57db504c 100644 --- a/serializer/src/main/java/org/apache/xml/serializer/Encodings.java +++ b/serializer/src/main/java/org/apache/xml/serializer/Encodings.java @@ -36,6 +36,12 @@ /** * Provides information about encodings. Depends on the Java runtime * to provides writers for the different encodings. + * + * NOTE: When a Java or MIME names appears more than once in the + * encodings.properties table, priority is given to the first instance + * seen. For example, MIME name ISO-8859-1 will be mapped to Java name + * ISO8859-1, even though the file includes synonyms such as ISO8859_1 + * and 8859-1. *

* This class is not a public API. It is only public because it * is used outside of this package. @@ -369,9 +375,9 @@ private static EncodingInfo[] loadEncodingInfo() mimeName = st.nextToken(); EncodingInfo ei = new EncodingInfo(mimeName, javaName, highChar); encodingInfo_list.add(ei); - _encodingTableKeyMime.put(mimeName.toUpperCase(), ei); + _encodingTableKeyMime.putIfAbsent(mimeName.toUpperCase(), ei); if (first) - _encodingTableKeyJava.put(javaName.toUpperCase(), ei); + _encodingTableKeyJava.putIfAbsent(javaName.toUpperCase(), ei); } } } diff --git a/serializer/src/main/resources/org/apache/xml/serializer/Encodings.properties b/serializer/src/main/resources/org/apache/xml/serializer/Encodings.properties index f1da1dbc1..c1e3d8fcc 100644 --- a/serializer/src/main/resources/org/apache/xml/serializer/Encodings.properties +++ b/serializer/src/main/resources/org/apache/xml/serializer/Encodings.properties @@ -37,6 +37,9 @@ # Higher values above this char might be in the encoding, although in the # case of this particular encoding there are no higher chars. # +# NOTE: When a Java or MIME names appears more than once in this +# table, priority is given to the first instance seen. For example, +# MIME name ISO-8859-1 will be mapped to Java name ISO8859-1. # # , #