本文整理汇总了Java中org.owasp.esapi.codecs.Codec.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Codec.encode方法的具体用法?Java Codec.encode怎么用?Java Codec.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.owasp.esapi.codecs.Codec
的用法示例。
在下文中一共展示了Codec.encode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import org.owasp.esapi.codecs.Codec; //导入方法依赖的package包/类
/**
* Set the parameter at index with supplied value using the supplied Codec to escape.
* @param index
* @param value
* @param codec
*/
public void set( int index, String value, Codec codec ) {
if ( index < 1 || index > parameters.length ) {
throw new IllegalArgumentException( "Attempt to set parameter " + index + " on a PreparedString with only " + parameters.length + " placeholders" );
}
String encoded = codec.encode( IMMUNE, value );
parameters[index-1] = encoded;
}
示例2: encodeForSQL
import org.owasp.esapi.codecs.Codec; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public String encodeForSQL(Codec codec, String input) {
if( input == null ) {
return null;
}
return codec.encode(IMMUNE_SQL, input);
}
示例3: encodeForOS
import org.owasp.esapi.codecs.Codec; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public String encodeForOS(Codec codec, String input) {
if( input == null ) {
return null;
}
return codec.encode( IMMUNE_OS, input);
}
示例4: testWindowsCodec
import org.owasp.esapi.codecs.Codec; //导入方法依赖的package包/类
/**
* Test of WindowsCodec
*/
public void testWindowsCodec() {
System.out.println("WindowsCodec");
Encoder instance = ESAPI.encoder();
Codec win = new WindowsCodec();
char[] immune = new char[0];
assertEquals(null, instance.encodeForOS(win, null));
PushbackString npbs = new PushbackString("n");
assertEquals(null, win.decodeCharacter(npbs));
PushbackString epbs = new PushbackString("");
assertEquals(null, win.decodeCharacter(epbs));
Character c = Character.valueOf('<');
PushbackString cpbs = new PushbackString(win.encodeCharacter(immune, c));
Character decoded = win.decodeCharacter(cpbs);
assertEquals(c, decoded);
String orig = "c:\\jeff";
String enc = win.encode(EncoderConstants.CHAR_ALPHANUMERICS, orig);
assertEquals(orig, win.decode(enc));
assertEquals(orig, win.decode(orig));
// TODO: Check that these are acceptable for Windows
assertEquals("c^:^\\jeff", instance.encodeForOS(win, "c:\\jeff"));
assertEquals("c^:^\\jeff", win.encode(immune, "c:\\jeff"));
assertEquals("dir^ ^&^ foo", instance.encodeForOS(win, "dir & foo"));
assertEquals("dir^ ^&^ foo", win.encode(immune, "dir & foo"));
}
示例5: testUnixCodec
import org.owasp.esapi.codecs.Codec; //导入方法依赖的package包/类
/**
* Test of UnixCodec
*/
public void testUnixCodec() {
System.out.println("UnixCodec");
Encoder instance = ESAPI.encoder();
Codec unix = new UnixCodec();
char[] immune = new char[0];
assertEquals(null, instance.encodeForOS(unix, null));
PushbackString npbs = new PushbackString("n");
assertEquals(null, unix.decodeCharacter(npbs));
Character c = Character.valueOf('<');
PushbackString cpbs = new PushbackString(unix.encodeCharacter(immune, c));
Character decoded = unix.decodeCharacter(cpbs);
assertEquals(c, decoded);
PushbackString epbs = new PushbackString("");
assertEquals(null, unix.decodeCharacter(epbs));
String orig = "/etc/passwd";
String enc = unix.encode(immune, orig);
assertEquals(orig, unix.decode(enc));
assertEquals(orig, unix.decode(orig));
// TODO: Check that these are acceptable for Unix hosts
assertEquals("c\\:\\\\jeff", instance.encodeForOS(unix, "c:\\jeff"));
assertEquals("c\\:\\\\jeff", unix.encode(immune, "c:\\jeff"));
assertEquals("dir\\ \\&\\ foo", instance.encodeForOS(unix, "dir & foo"));
assertEquals("dir\\ \\&\\ foo", unix.encode(immune, "dir & foo"));
// Unix paths (that must be encoded safely)
// TODO: Check that these are acceptable for Unix
assertEquals("\\/etc\\/hosts", instance.encodeForOS(unix, "/etc/hosts"));
assertEquals("\\/etc\\/hosts\\;\\ ls\\ -l", instance.encodeForOS(unix, "/etc/hosts; ls -l"));
}