]> source.dussan.org Git - gitblit.git/commitdiff
Alias UTF-9 and UTF-18 as UTF-8 in JGit 51/151/1
authorJames Moger <james.moger@gitblit.com>
Thu, 4 Sep 2014 18:19:46 +0000 (14:19 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 4 Sep 2014 18:19:46 +0000 (14:19 -0400)
src/main/java/com/gitblit/manager/RepositoryManager.java

index 0160363e81793a18d0d389292103ce4707e294f8..a8b23237354faf35d646ff034a0e690692c3afec 100644 (file)
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.lang.reflect.Field;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.Charset;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -52,6 +53,7 @@ import org.eclipse.jgit.storage.file.FileBasedConfig;
 import org.eclipse.jgit.storage.file.WindowCacheConfig;
 import org.eclipse.jgit.util.FS;
 import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.RawParseUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1895,6 +1897,18 @@ public class RepositoryManager implements IRepositoryManager {
                } catch (IllegalArgumentException e) {
                        logger.error("Failed to configure JGit parameters!", e);
                }
+
+               try {
+                       // issue-486/ticket-151: UTF-9 & UTF-18
+                       Field field = RawParseUtils.class.getDeclaredField("encodingAliases");
+                       field.setAccessible(true);
+                       Map<String, Charset> encodingAliases = (Map<String, Charset>) field.get(null);
+                       encodingAliases.put("utf-9", RawParseUtils.UTF8_CHARSET);
+                       encodingAliases.put("utf-18", RawParseUtils.UTF8_CHARSET);
+                       logger.info("Alias UTF-9 & UTF-18 encodings as UTF-8 in JGit");
+               } catch (Throwable t) {
+                       logger.error("Failed to inject UTF-9 & UTF-18 encoding aliases into JGit", t);
+               }
        }
 
        protected void configureCommitCache() {