Browse Source

Remove UTF-8 checking duplication in Config lib subclasses

Change-Id: Ib9f0ae8207000a36c5bf1a92fcc2c32efc4c0984
Signed-off-by: Marco Miller <marco.miller@ericsson.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.5
Marco Miller 9 years ago committed by Matthias Sohn
parent
commit
e5a9915a92
  1. 3
      org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java
  2. 13
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
  3. 3
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

3
org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java

@ -80,8 +80,7 @@ public class BlobBasedConfig extends Config {
throws ConfigInvalidException { throws ConfigInvalidException {
super(base); super(base);
final String decoded; final String decoded;
if (blob.length >= 3 && blob[0] == (byte) 0xEF if (isUtf8(blob)) {
&& blob[1] == (byte) 0xBB && blob[2] == (byte) 0xBF) {
decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET,
blob, 3, blob.length); blob, 3, blob.length);
} else { } else {

13
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

@ -1108,6 +1108,19 @@ public class Config {
state.set(newState()); state.set(newState());
} }
/**
* Check if bytes should be treated as UTF-8 or not.
*
* @param bytes
* the bytes to check encoding for.
* @return true if bytes should be treated as UTF-8, false otherwise.
* @since 4.4
*/
protected boolean isUtf8(final byte[] bytes) {
return bytes.length >= 3 && bytes[0] == (byte) 0xEF
&& bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF;
}
private static String readSectionName(final StringReader in) private static String readSectionName(final StringReader in)
throws ConfigInvalidException { throws ConfigInvalidException {
final StringBuilder name = new StringBuilder(); final StringBuilder name = new StringBuilder();

3
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

@ -147,8 +147,7 @@ public class FileBasedConfig extends StoredConfig {
snapshot = newSnapshot; snapshot = newSnapshot;
} else { } else {
final String decoded; final String decoded;
if (in.length >= 3 && in[0] == (byte) 0xEF if (isUtf8(in)) {
&& in[1] == (byte) 0xBB && in[2] == (byte) 0xBF) {
decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET,
in, 3, in.length); in, 3, in.length);
utf8Bom = true; utf8Bom = true;

Loading…
Cancel
Save