本文整理汇总了Java中org.owasp.encoder.Encode.forHtml方法的典型用法代码示例。如果您正苦于以下问题:Java Encode.forHtml方法的具体用法?Java Encode.forHtml怎么用?Java Encode.forHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.owasp.encoder.Encode
的用法示例。
在下文中一共展示了Encode.forHtml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forHtml
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
/**
* Encodes for HTML text content and text attributes.
*
* @param input HTML input, may be null
*
* @return Encoded HTML text, empty string if anything goes wrong
*/
public String forHtml( String input )
{
if( isEmpty( input ) )
{
return EMPTY;
}
try
{
return Encode.forHtml( input );
}
catch( Exception ex )
{
LOG.error( "Encoding for HTML error, will return empty string: {}", ex.getMessage(), ex );
return EMPTY;
}
}
示例2: doPost
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
String name = request.getParameter("outputEscapedName");
log.info("Received {} as name", name);
response.setContentType("text/html");
try (PrintWriter out = response.getWriter()) {
out.println("<html><head>");
out.println("<title>Cross-Site Scripting (XSS) - Output Escaping</title>");
out.println("<link rel='stylesheet' type='text/css' href='resources/css/styles.css' />");
out.println("</head>");
out.println("<body>");
out.println("<h1>Cross-Site Scripting (XSS) - Output Escaping</h1>");
out.println("<p title='Hello " + Encode.forHtmlAttribute(name) + "'><strong>Hello </strong>");
Encode.forHtml(out, name);
out.println("</p>");
out.println("<p><a href='index.jsp'>Home</a></p>");
out.println("</body></html>");
} catch (IOException ex) {
log.error(ex.getMessage(), ex);
}
}
示例3: testGetJobStatusServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testGetJobStatusServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( GetJobStatusServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
getJobStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例4: testStopJobServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testStopJobServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StopJobServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
stopJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例5: testRemoveTransServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testRemoveTransServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( RemoveTransServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
removeTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例6: testPauseTransServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testPauseTransServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( PauseTransServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
pauseTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例7: testCleanupTransServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testCleanupTransServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( CleanupTransServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
cleanupTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例8: testRemoveJobServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testRemoveJobServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( RemoveJobServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
removeJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例9: testStopTransServletEscapesHtmlWhenTransFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testStopTransServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
Trans mockTrans = mock( Trans.class );
TransMeta mockTransMeta = mock( TransMeta.class );
LogChannelInterface mockChannelInterface = mock( LogChannelInterface.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StopTransServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
when( mockTransformationMap.getTransformation( any( CarteObjectEntry.class ) ) ).thenReturn( mockTrans );
when( mockTrans.getLogChannel() ).thenReturn( mockChannelInterface );
when( mockTrans.getLogChannelId() ).thenReturn( "test" );
when( mockTrans.getTransMeta() ).thenReturn( mockTransMeta );
when( mockTransMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) );
stopTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例10: testStartTransServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testStartTransServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StartTransServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
startTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例11: testStartTransServletEscapesHtmlWhenTransFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testStartTransServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
Trans mockTrans = mock( Trans.class );
TransMeta mockTransMeta = mock( TransMeta.class );
LogChannelInterface mockChannelInterface = mock( LogChannelInterface.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StartTransServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
when( mockTransformationMap.getTransformation( any( CarteObjectEntry.class ) ) ).thenReturn( mockTrans );
when( mockTrans.getLogChannel() ).thenReturn( mockChannelInterface );
when( mockTrans.getLogChannelId() ).thenReturn( "test" );
when( mockTrans.getTransMeta() ).thenReturn( mockTransMeta );
when( mockTransMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) );
startTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例12: testGetTransStatusServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testGetTransStatusServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( GetTransStatusServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
getTransStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例13: testStartJobServletEscapesHtmlWhenTransNotFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testStartJobServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StartJobServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
startJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例14: testRemoveTransServletEscapesHtmlWhenTransFound
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testRemoveTransServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
Trans mockTrans = mock( Trans.class );
TransMeta mockTransMeta = mock( TransMeta.class );
LogChannelInterface mockChannelInterface = mock( LogChannelInterface.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( RemoveTransServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
when( mockTransformationMap.getTransformation( any( CarteObjectEntry.class ) ) ).thenReturn( mockTrans );
when( mockTrans.getLogChannel() ).thenReturn( mockChannelInterface );
when( mockTrans.getLogChannelId() ).thenReturn( "test" );
when( mockTrans.getTransMeta() ).thenReturn( mockTransMeta );
when( mockTransMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) );
removeTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H3", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
示例15: escape
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
/**
* Eliminate dangerous chars in node name.
* TODO Keep on sync with uploader:com.openkm.applet.Util.escape(String)
* TODO Keep on sync with wsImporter:com.openkm.importer.Util.escape(String)
*/
public static String escape(String name) {
String ret = cleanup(name);
// Fix XSS issues
ret = Encode.forHtml(ret);
return ret;
}