diff options
Diffstat (limited to 'src')
3 files changed, 18 insertions, 20 deletions
diff --git a/src/main/bugtraq/com/syntevo/bugtraq/BugtraqConfig.java b/src/main/bugtraq/com/syntevo/bugtraq/BugtraqConfig.java index bce0bd8a..ca0b317f 100644 --- a/src/main/bugtraq/com/syntevo/bugtraq/BugtraqConfig.java +++ b/src/main/bugtraq/com/syntevo/bugtraq/BugtraqConfig.java @@ -31,6 +31,9 @@ package com.syntevo.bugtraq; import java.io.File; import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -55,6 +58,8 @@ import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static java.nio.charset.StandardCharsets.UTF_8; + public final class BugtraqConfig { // Constants ============================================================== @@ -229,7 +234,7 @@ public final class BugtraqConfig { FileMode entmode = tw.getFileMode(0); if (FileMode.REGULAR_FILE == entmode) { ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB); - content = new String(ldr.getCachedBytes(), commit.getEncoding()); + content = new String(ldr.getCachedBytes(), guessEncoding(commit)); break; } } @@ -265,6 +270,15 @@ public final class BugtraqConfig { return baseConfig; } + @NotNull + private static Charset guessEncoding(RevCommit commit) { + try { + return commit.getEncoding(); + } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { + return UTF_8; + } + } + @Nullable private static String getString(@Nullable String subsection, @NotNull String key, @NotNull Config config, @Nullable Config baseConfig) { final String value = config.getString(BUGTRAQ, subsection, key); diff --git a/src/main/java/com/gitblit/manager/RepositoryManager.java b/src/main/java/com/gitblit/manager/RepositoryManager.java index 2be65873..8d18c811 100644 --- a/src/main/java/com/gitblit/manager/RepositoryManager.java +++ b/src/main/java/com/gitblit/manager/RepositoryManager.java @@ -21,7 +21,6 @@ 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; @@ -53,7 +52,6 @@ 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; @@ -1944,20 +1942,6 @@ 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 - // issue-560/ticket-237: 'UTF8' - Field field = RawParseUtils.class.getDeclaredField("encodingAliases"); - field.setAccessible(true); - Map<String, Charset> encodingAliases = (Map<String, Charset>) field.get(null); - encodingAliases.put("'utf8'", RawParseUtils.UTF8_CHARSET); - encodingAliases.put("utf-9", RawParseUtils.UTF8_CHARSET); - encodingAliases.put("utf-18", RawParseUtils.UTF8_CHARSET); - logger.info("Alias 'UTF8', 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() { diff --git a/src/main/java/com/gitblit/utils/BugtraqProcessor.java b/src/main/java/com/gitblit/utils/BugtraqProcessor.java index 67f220f6..8ecf948a 100644 --- a/src/main/java/com/gitblit/utils/BugtraqProcessor.java +++ b/src/main/java/com/gitblit/utils/BugtraqProcessor.java @@ -155,10 +155,10 @@ public class BugtraqProcessor { formatter.formatLogMessage(text, new BugtraqOutputHandler(sb)); text = sb.toString(); } - } catch (IOException e) { - logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e); } catch (ConfigInvalidException e) { - logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e); + logger.warn("Bugtraq config for {} is invalid!", repositoryName, e); + } catch (Exception e) { + logger.warn("Failed to parse message through Bugtraq.", e); } return text; |