diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.java index b0916c7d8..abe2bbd06 100644 --- a/source/de/anomic/server/serverObjects.java +++ b/source/de/anomic/server/serverObjects.java @@ -64,6 +64,8 @@ public class serverObjects extends HashMap implements Cloneable private static final long serialVersionUID = 1L; private boolean localized = true; + + private final static char BOM = '\uFEFF'; // ByteOrderMark character that may appear at beginnings of Strings (Browser may append that) public serverObjects() { super(); @@ -76,6 +78,12 @@ public class serverObjects extends HashMap implements Cloneable public serverObjects(final Map input) { super(input); } + + private static final String removeBOM(String s) { + if (s == null || s.length() == 0) return s; + if (s.charAt(0) == BOM) return s.substring(1); + return s; + } /** * Add a key-value pair of Objects to the map. @@ -253,13 +261,13 @@ public class serverObjects extends HashMap implements Cloneable // string variant public String get(final String key, final String dflt) { - final Object result = super.get(key); + final String result = removeBOM(super.get(key)); if (result == null) return dflt; - return (String) result; + return result; } public int getInt(final String key, final int dflt) { - final String s = super.get(key); + final String s = removeBOM(super.get(key)); if (s == null) return dflt; try { return Integer.parseInt(s); @@ -269,7 +277,7 @@ public class serverObjects extends HashMap implements Cloneable } public long getLong(final String key, final long dflt) { - final String s = super.get(key); + final String s = removeBOM(super.get(key)); if (s == null) return dflt; try { return Long.parseLong(s); @@ -279,7 +287,7 @@ public class serverObjects extends HashMap implements Cloneable } public double getDouble(final String key, final double dflt) { - final String s = super.get(key); + final String s = removeBOM(super.get(key)); if (s == null) return dflt; try { return Double.parseDouble(s);