* Implement lenient macro parse mode if something smells fishy.
* Allow empty skin to override.
This commit is contained in:
parent
7161df38b2
commit
170af5b845
1 changed files with 49 additions and 33 deletions
|
@ -181,7 +181,7 @@ public final class Skin {
|
||||||
* @return true if this skin contains a main skin
|
* @return true if this skin contains a main skin
|
||||||
*/
|
*/
|
||||||
public boolean hasMainskin() {
|
public boolean hasMainskin() {
|
||||||
return length - offset > 0;
|
return length - offset > 0 || subskins == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,11 +356,44 @@ public final class Skin {
|
||||||
/**
|
/**
|
||||||
* Create and parse a new macro.
|
* Create and parse a new macro.
|
||||||
* @param start the start of the macro within the skin source
|
* @param start the start of the macro within the skin source
|
||||||
* @param offset offset of the macro content from the start index
|
* @param macroOffset offset of the macro content from the start index
|
||||||
*/
|
*/
|
||||||
public Macro(int start, int offset) {
|
public Macro(int start, int macroOffset) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
|
|
||||||
|
int i = parse(macroOffset, false);
|
||||||
|
|
||||||
|
if (isSubskinMacro) {
|
||||||
|
if (i + 1 < length && source[i] == '\r' && source[i + 1] == '\n')
|
||||||
|
end = Math.min(length, i + 2);
|
||||||
|
else if (i < length && (source[i] == '\r' || source[i] == '\n'))
|
||||||
|
end = Math.min(length, i + 1);
|
||||||
|
else
|
||||||
|
end = Math.min(length, i);
|
||||||
|
} else {
|
||||||
|
end = Math.min(length, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
path = StringUtils.split(name, ".");
|
||||||
|
if (path.length <= 1) {
|
||||||
|
handlerType = HANDLER_GLOBAL;
|
||||||
|
} else {
|
||||||
|
String handlerName = path[0];
|
||||||
|
if ("this".equalsIgnoreCase(handlerName)) {
|
||||||
|
handlerType = HANDLER_THIS;
|
||||||
|
} else if ("response".equalsIgnoreCase(handlerName)) {
|
||||||
|
handlerType = HANDLER_RESPONSE;
|
||||||
|
} else if ("request".equalsIgnoreCase(handlerName)) {
|
||||||
|
handlerType = HANDLER_REQUEST;
|
||||||
|
} else if ("session".equalsIgnoreCase(handlerName)) {
|
||||||
|
handlerType = HANDLER_SESSION;
|
||||||
|
} else if ("param".equalsIgnoreCase(handlerName)) {
|
||||||
|
handlerType = HANDLER_PARAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int parse(int macroOffset, boolean lenient) {
|
||||||
int state = PARSE_MACRONAME;
|
int state = PARSE_MACRONAME;
|
||||||
boolean escape = false;
|
boolean escape = false;
|
||||||
char quotechar = '\u0000';
|
char quotechar = '\u0000';
|
||||||
|
@ -369,7 +402,7 @@ public final class Skin {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for (i = start + offset; i < length - 1; i++) {
|
for (i = start + macroOffset; i < length - 1; i++) {
|
||||||
|
|
||||||
switch (source[i]) {
|
switch (source[i]) {
|
||||||
|
|
||||||
|
@ -390,7 +423,8 @@ public final class Skin {
|
||||||
|
|
||||||
case '%':
|
case '%':
|
||||||
|
|
||||||
if ((state != PARSE_PARAM || quotechar == '\u0000') && source[i + 1] == '>') {
|
if ((state != PARSE_PARAM || quotechar == '\u0000' || lenient)
|
||||||
|
&& source[i + 1] == '>') {
|
||||||
state = PARSE_DONE;
|
state = PARSE_DONE;
|
||||||
break loop;
|
break loop;
|
||||||
}
|
}
|
||||||
|
@ -516,18 +550,16 @@ public final class Skin {
|
||||||
b.append(source[i]);
|
b.append(source[i]);
|
||||||
escape = false;
|
escape = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
i += 2;
|
if (i == length - 2 && !lenient &&
|
||||||
if (isSubskinMacro) {
|
(state != PARSE_DONE ||quotechar != '\u0000')) {
|
||||||
if (i + 1 < length && source[i] == '\r' && source[i + 1] == '\n')
|
filterChain = null;
|
||||||
end = Math.min(length, i + 2);
|
name = null;
|
||||||
else if (i < length && (source[i] == '\r' || source[i] == '\n'))
|
standardParams = new StandardParams();
|
||||||
end = Math.min(length, i + 1);
|
namedParams = null;
|
||||||
else
|
positionalParams = null;
|
||||||
end = Math.min(length, i);
|
return parse(macroOffset, true);
|
||||||
} else {
|
}
|
||||||
end = Math.min(length, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.length() > 0) {
|
if (b.length() > 0) {
|
||||||
|
@ -542,23 +574,7 @@ public final class Skin {
|
||||||
app.logError("Unterminated Macro Tag: " +this);
|
app.logError("Unterminated Macro Tag: " +this);
|
||||||
}
|
}
|
||||||
|
|
||||||
path = StringUtils.split(name, ".");
|
return i + 2;
|
||||||
if (path.length <= 1) {
|
|
||||||
handlerType = HANDLER_GLOBAL;
|
|
||||||
} else {
|
|
||||||
String handlerName = path[0];
|
|
||||||
if ("this".equalsIgnoreCase(handlerName)) {
|
|
||||||
handlerType = HANDLER_THIS;
|
|
||||||
} else if ("response".equalsIgnoreCase(handlerName)) {
|
|
||||||
handlerType = HANDLER_RESPONSE;
|
|
||||||
} else if ("request".equalsIgnoreCase(handlerName)) {
|
|
||||||
handlerType = HANDLER_REQUEST;
|
|
||||||
} else if ("session".equalsIgnoreCase(handlerName)) {
|
|
||||||
handlerType = HANDLER_SESSION;
|
|
||||||
} else if ("param".equalsIgnoreCase(handlerName)) {
|
|
||||||
handlerType = HANDLER_PARAM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object parseParameter(String str) {
|
private Object parseParameter(String str) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue