Console: Fix log file size config bug on /configlogging bug (ticket #1996)

This commit is contained in:
str4d
2017-07-07 17:25:25 +00:00
parent 87d6c302e6
commit d8831151fe
3 changed files with 29 additions and 17 deletions

View File

@ -23,10 +23,7 @@ public class ConfigLoggingHelper extends HelperBase {
public String getMaxFileSize() {
int bytes = _context.logManager().getFileSize();
if (bytes <= 0) return "1.00 MB";
// "&nbsp;" comes back in the POST as 0xc2 0xa0
// non-breaking space is U+00A0 which is 0xc2 0xa0 in UTF-8.
// we could figure out where the UTF-8 problem is but why bother.
return DataHelper.formatSize2(bytes).replace("&nbsp;", " ") + 'B';
return DataHelper.formatSize2(bytes, false) + 'B';
}
public String getLogLevelTable() {
StringBuilder buf = new StringBuilder(32*1024);

View File

@ -1553,10 +1553,21 @@ public class DataHelper {
/**
* Like formatSize but with a non-breaking space after the number
* This seems consistent with most style guides out there.
* Use only in HTML
* @since 0.7.14
* Use only in HTML, and not inside form values (use
* formatSize2(bytes, false) there instead).
* @since 0.7.14, uses thin non-breaking space since 0.9.31
*/
public static String formatSize2(long bytes) {
return formatSize2(bytes, true);
}
/**
* Like formatSize but with a space after the number
* This seems consistent with most style guides out there.
* @param nonBreaking use an HTML thin non-breaking space (&#8239;)
* @since 0.9.31
*/
public static String formatSize2(long bytes, boolean nonBreaking) {
double val = bytes;
int scale = 0;
while (val >= 1024) {
@ -1568,17 +1579,18 @@ public class DataHelper {
// Replace &nbsp; with thin non-breaking space &#8239; (more consistent/predictable width between fonts & point sizes)
String str = fmt.format(val);
String space = nonBreaking ? "&#8239;" : " ";
String str = fmt.format(val) + space;
switch (scale) {
case 1: return str + "&#8239;K";
case 2: return str + "&#8239;M";
case 3: return str + "&#8239;G";
case 4: return str + "&#8239;T";
case 5: return str + "&#8239;P";
case 6: return str + "&#8239;E";
case 7: return str + "&#8239;Z";
case 8: return str + "&#8239;Y";
default: return bytes + "&#8239;";
case 1: return str + "K";
case 2: return str + "M";
case 3: return str + "G";
case 4: return str + "T";
case 5: return str + "P";
case 6: return str + "E";
case 7: return str + "Z";
case 8: return str + "Y";
default: return bytes + space;
}
}

View File

@ -1,3 +1,6 @@
2017-07-06 str4d
* Console: Fix log file size config bug on /configlogging bug (ticket #1996)
2017-07-02 str4d
* Console:
- Show correct icon for "Firewalled" network status