private final String[] store;
/**
- * Creates a new SprintfCommand based on its pre-parsed contents
+ * Creates a new SprintfCommand based on its pre-parsed contents.
*
* @param text
* a string with <code>{0},{1},..</code> as placeholders.
* Creates a new SprintfCommand that is parsed as from template source.
*
* @param content
- * the part from the template that is to be parsed
+ * the part from the template that is to be parsed.
*/
protected SprintfCommand(String content) {
StringBuffer raw = new StringBuffer();
Matcher m = replacant.matcher(parts);
int pos = 0;
while (m.find()) {
- out.print(HTMLEncoder.encodeHTML(parts.substring(pos, m.start())));
+ out.print(escape(vars, parts.substring(pos, m.start())));
String var = store[Integer.parseInt(m.group(1))];
if (var.startsWith("$!")) {
Template.outputVar(out, l, vars, var.substring(3, var.length() - 1), true);
pos = m.end();
}
- out.print(HTMLEncoder.encodeHTML(parts.substring(pos)));
+ out.print(escape(vars, parts.substring(pos)));
+ }
+
+ private String escape(Map<String, Object> vars, String target) {
+ if (vars.containsKey(OUT_KEY_PLAIN)) {
+ return target;
+ }
+ return HTMLEncoder.encodeHTML(target);
}
@Override
* as placeholders.
* @param vars
* the variables to put into the placeholders.
- * @return the constructed {@link Outputable}
+ * @return the constructed {@link Outputable}.
*/
- public static Outputable createSimple(String msg, String... vars) {
+ public static Outputable createSimple(String msg, Object... vars) {
HashMap<String, Object> scope = new HashMap<>();
String[] store = new String[vars.length];
for (int i = 0; i < vars.length; i++) {