提交 e9a38b5d 编写于 作者: K kohsuke

added base64 validation method.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17873 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c492fdda
...@@ -582,6 +582,8 @@ public abstract class FormFieldValidator { ...@@ -582,6 +582,8 @@ public abstract class FormFieldValidator {
* Verifies that the 'value' parameter is correct base64 encoded text. * Verifies that the 'value' parameter is correct base64 encoded text.
* *
* @since 1.257 * @since 1.257
* @deprecated as of 1.305
* Use {@link FormValidation#validateBase64(String, boolean, boolean, String)} instead.
*/ */
public static class Base64 extends FormFieldValidator { public static class Base64 extends FormFieldValidator {
private final boolean allowWhitespace; private final boolean allowWhitespace;
......
...@@ -306,6 +306,35 @@ public abstract class FormValidation extends IOException implements HttpResponse ...@@ -306,6 +306,35 @@ public abstract class FormValidation extends IOException implements HttpResponse
} }
} }
/**
* Makes sure that the given string is a base64 encoded text.
*
* @param allowWhitespace
* if you allow whitespace (CR,LF,etc) in base64 encoding
* @param allowEmpty
* Is empty string allowed?
* @param errorMessage
* Error message.
* @since 1.305
*/
public static FormValidation validateBase64(String value, boolean allowWhitespace, boolean allowEmpty, String errorMessage) {
try {
String v = value;
if(!allowWhitespace) {
if(v.indexOf(' ')>=0 || v.indexOf('\n')>=0)
return error(errorMessage);
}
v=v.trim();
if(!allowEmpty && v.length()==0)
return error(errorMessage);
com.trilead.ssh2.crypto.Base64.decode(v.toCharArray());
return ok();
} catch (IOException e) {
return error(errorMessage);
}
}
/** /**
* Convenient base class for checking the validity of URLs. * Convenient base class for checking the validity of URLs.
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册