Log expected and actual values for better decoding diagnosability
package jenkins.diagnostics;
import hudson.Extension;
+import hudson.Util;
import hudson.model.AdministrativeMonitor;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;
@@ -9,6 +10,9 @@ import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import static hudson.Util.fixEmpty;
@@ -16,6 +20,8 @@ import static hudson.Util.fixEmpty;
@Extension
public class URICheckEncodingMonitor extends AdministrativeMonitor {
+ private static final Logger LOGGER = Logger.getLogger(URICheckEncodingMonitor.class.getName());
+
public boolean isCheckEnabled() {
return !"ISO-8859-1".equalsIgnoreCase(System.getProperty("file.encoding"));
}
@@ -35,8 +41,13 @@ public class URICheckEncodingMonitor extends AdministrativeMonitor {
// expected is non-ASCII String
final String expected = "\u57f7\u4e8b";
final String value = fixEmpty(request.getParameter("value"));
- if (!expected.equals(value))
+
+ if (!expected.equals(value)) {
+ String expectedHex = Util.toHexString(expected.getBytes(StandardCharsets.UTF_8));
+ String valueHex = Util.toHexString(value.getBytes(StandardCharsets.UTF_8));
+ LOGGER.log(Level.CONFIG, "Expected to receive: " + expected + " (" + expectedHex + ") but got: " + value + " (" + valueHex + ")");
return FormValidation.warningWithMarkup(hudson.model.Messages.Hudson_NotUsesUTF8ToDecodeURL());
+ }
return FormValidation.ok();
}
}
