WW-4972 Adds another test case to cover escaping

This commit is contained in:
Lukasz Lenart
2019-01-03 12:50:55 +01:00
parent 6f05603ab0
commit 0ecb482a11
2 changed files with 46 additions and 0 deletions
@@ -20,12 +20,17 @@ package org.apache.struts2.views.freemarker;
import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.Version;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.views.jsp.StrutsMockServletContext;
import javax.servlet.ServletContext;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
/**
* Test case for FreemarkerManager
@@ -77,6 +82,24 @@ public class FreemarkerManagerTest extends StrutsInternalTestCase {
assertEquals(Configuration.VERSION_2_3_0, manager.config.getIncompatibleImprovements());
}
public void testIncompatibleImprovementsWithTemplate() throws Exception {
// given
FreemarkerManager manager = new FreemarkerManager();
container.inject(manager);
Configuration configuration = manager.getConfiguration(servletContext);
Template tpl = configuration.getTemplate("org/apache/struts2/views/freemarker/incompatible-improvements.ftl");
// when
Writer out = new StringWriter();
Map<String, String> model = new HashMap<>();
model.put("error", "It's an error message");
tpl.process(model, out);
// then
assertEquals("<input type=\"text\" onclick=\"this.alert('It&#39;s an error message')\"/>", out.toString());
}
public void testIncompatibleImprovementsByServletContext() throws Exception {
// given
servletContext.setInitParameter("freemarker.incompatible_improvements", "2.3.0");
@@ -0,0 +1,23 @@
<#--
/*
* $Id: someFreeMarkerFile.ftl 590812 2007-10-31 20:32:54Z apetrelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<input type="text" onclick="this.alert('${error}')"/>