Taint cleanup from Dave.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2533 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -116,9 +116,9 @@ public class MessageManager
|
|||||||
return "[null message key]";
|
return "[null message key]";
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the key is tainted, just strip the taint character
|
// if the key is tainted, just return the untainted key
|
||||||
if (path.startsWith(MessageUtil.TAINT_CHAR)) {
|
if (MessageUtil.isTainted(path)) {
|
||||||
return path.substring(1);
|
return MessageUtil.untaint(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt to determine whether or not this is a compound key
|
// attempt to determine whether or not this is a compound key
|
||||||
@@ -128,13 +128,13 @@ public class MessageManager
|
|||||||
String argstr = path.substring(tidx+1);
|
String argstr = path.substring(tidx+1);
|
||||||
String[] args = StringUtil.split(argstr, "|");
|
String[] args = StringUtil.split(argstr, "|");
|
||||||
// unescape and translate the arguments
|
// unescape and translate the arguments
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int ii = 0; ii < args.length; ii++) {
|
||||||
// if the argument is tainted, do no further translation (it might contain |s or
|
// if the argument is tainted, do no further translation (it might contain |s or
|
||||||
// other fun stuff)
|
// other fun stuff)
|
||||||
if (args[i].startsWith(MessageUtil.TAINT_CHAR)) {
|
if (MessageUtil.isTainted(args[ii])) {
|
||||||
args[i] = MessageUtil.unescape(args[i].substring(1));
|
args[ii] = MessageUtil.unescape(MessageUtil.untaint(args[ii]));
|
||||||
} else {
|
} else {
|
||||||
args[i] = getMessage(req, MessageUtil.unescape(args[i]));
|
args[ii] = getMessage(req, MessageUtil.unescape(args[ii]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getMessage(req, key, args);
|
return getMessage(req, key, args);
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ package com.samskivert.text;
|
|||||||
*/
|
*/
|
||||||
public class MessageUtil
|
public class MessageUtil
|
||||||
{
|
{
|
||||||
/** Text prefixed by this character will be considered tainted when doing recursive
|
|
||||||
* translations and won't be translated. */
|
|
||||||
public static final String TAINT_CHAR = "~";
|
|
||||||
|
|
||||||
/** Used to mark fully qualified message keys. */
|
/** Used to mark fully qualified message keys. */
|
||||||
public static final String QUAL_PREFIX = "%";
|
public static final String QUAL_PREFIX = "%";
|
||||||
|
|
||||||
@@ -46,6 +42,24 @@ public class MessageUtil
|
|||||||
return TAINT_CHAR + text;
|
return TAINT_CHAR + text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not the provided string is tainted. See {@link #taint()}. Null strings
|
||||||
|
* are considered untainted.
|
||||||
|
*/
|
||||||
|
public static boolean isTainted (String text)
|
||||||
|
{
|
||||||
|
return text != null && text.startsWith(TAINT_CHAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the tainting character added to a string by {@link #taint()}. If the provided string
|
||||||
|
* is not tainted, this silently returns the originally provided string.
|
||||||
|
*/
|
||||||
|
public static String untaint (String text)
|
||||||
|
{
|
||||||
|
return isTainted(text) ? text.substring(TAINT_CHAR.length()) : text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Composes a message key with an array of arguments. The message can subsequently be
|
* Composes a message key with an array of arguments. The message can subsequently be
|
||||||
* decomposed and translated without prior knowledge of how many arguments were provided.
|
* decomposed and translated without prior knowledge of how many arguments were provided.
|
||||||
@@ -220,4 +234,8 @@ public class MessageUtil
|
|||||||
|
|
||||||
return qualifiedKey.substring(qsidx+1);
|
return qualifiedKey.substring(qsidx+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Text prefixed by this character will be considered tainted when doing recursive
|
||||||
|
* translations and won't be translated. */
|
||||||
|
protected static final String TAINT_CHAR = "~";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user