Freemarker中有类TemplateCache其中方法:
private static String normalizeName(String name) {
// Disallow 0 for security reasons.
if (name.indexOf(0) != -1) return null;
for(;;) {
int parentDirPathLoc = name.indexOf(PARENT_DIR_PATH);
if(parentDirPathLoc == 0) {
// If it starts with /../, then it reaches outside the template
// root.
return null;
}
if(parentDirPathLoc == -1) {
if(name.startsWith(PARENT_DIR_PATH_PREFIX)) {
// Another attempt to reach out of template root.
return null;
}
break;
}
int previousSlashLoc = name.lastIndexOf(SLASH, parentDirPathLoc - 1);
name = name.substring(0, previousSlashLoc + 1) +
name.substring(parentDirPathLoc + PARENT_DIR_PATH.length());
}
for(;;) {
int currentDirPathLoc = name.indexOf(CURRENT_DIR_PATH);
if(currentDirPathLoc == -1) {
if(name.startsWith(CURRENT_DIR_PATH_PREFIX)) {
name = name.substring(CURRENT_DIR_PATH_PREFIX.length());
}
break;
}
name = name.substring(0, currentDirPathLoc) +
name.substring(currentDirPathLoc + CURRENT_DIR_PATH.length() - 1);
}
// Editing can leave us with a leading slash; strip it.
if(name.length() > 1 && name.charAt(0) == SLASH) {
name = name.substring(1);
}
return name;
}
先记下来以后再研究