Fixed YamlConfiguration creating empty lines when reading a file with no contents, and made it trim the initial newlines of any existing config header

By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot
2012-01-08 23:29:33 +00:00
parent 5fc8f4f576
commit e73be72fae
2 changed files with 30 additions and 6 deletions

View File

@@ -148,6 +148,7 @@ public class YamlConfiguration extends FileConfiguration {
String[] lines = input.split("\r?\n", -1);
StringBuilder result = new StringBuilder();
boolean readingHeader = true;
boolean foundHeader = false;
for (int i = 0; (i < lines.length) && (readingHeader); i++) {
String line = lines[i];
@@ -160,9 +161,11 @@ public class YamlConfiguration extends FileConfiguration {
if (line.length() > COMMENT_PREFIX.length()) {
result.append(line.substring(COMMENT_PREFIX.length()));
}
} else if (line.length() == 0) {
foundHeader = true;
} else if ((foundHeader) && (line.length() == 0)) {
result.append("\n");
} else {
} else if (foundHeader) {
readingHeader = false;
}
}