From d8831151fe7b0c3e77cc696e134173aed7fca2c7 Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 7 Jul 2017 17:25:25 +0000 Subject: [PATCH] Console: Fix log file size config bug on /configlogging bug (ticket #1996) --- .../i2p/router/web/ConfigLoggingHelper.java | 5 +-- core/java/src/net/i2p/data/DataHelper.java | 38 ++++++++++++------- history.txt | 3 ++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigLoggingHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigLoggingHelper.java index 3e8ef1cdd1..730e684e89 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigLoggingHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigLoggingHelper.java @@ -23,10 +23,7 @@ public class ConfigLoggingHelper extends HelperBase { public String getMaxFileSize() { int bytes = _context.logManager().getFileSize(); if (bytes <= 0) return "1.00 MB"; - // " " 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(" ", " ") + 'B'; + return DataHelper.formatSize2(bytes, false) + 'B'; } public String getLogLevelTable() { StringBuilder buf = new StringBuilder(32*1024); diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index e4e322c8de..f9fdc7e6df 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -1549,14 +1549,25 @@ public class DataHelper { default: return bytes + ""; } } - + /** * 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 ( ) + * @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   with thin non-breaking space   (more consistent/predictable width between fonts & point sizes) - String str = fmt.format(val); + String space = nonBreaking ? " " : " "; + String str = fmt.format(val) + space; switch (scale) { - 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 + " "; + 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; } } diff --git a/history.txt b/history.txt index 6649f6cc3f..3f84434e1e 100644 --- a/history.txt +++ b/history.txt @@ -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