Skip to content

Commit

Permalink
#326 improve fix
Browse files Browse the repository at this point in the history
  • Loading branch information
casid committed Mar 21, 2024
1 parent 361c12f commit e8fca09
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions jte/src/main/java/gg/jte/compiler/TemplateParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,20 +754,22 @@ private void interceptHtmlTags() {
visitor.onError("Unclosed tag <" + currentHtmlTag.name + ">, expected " + "</" + currentHtmlTag.name + ">, got </" + tagName + ">.");
}
tagClosed = true;
} else if (!currentHtmlTag.attributesProcessed && !Character.isWhitespace(currentChar) && currentChar != '/' && currentChar != '=' && currentHtmlTag.isCurrentAttributeComplete()) {
} else if (!currentHtmlTag.attributesProcessed && !Character.isWhitespace(currentChar) && currentChar != '/' && currentHtmlTag.isCurrentAttributeComplete()) {
HtmlAttribute attribute = parseHtmlAttribute();
if (attribute != null) {
htmlPolicy.validateHtmlAttribute(currentHtmlTag, attribute);

if (attribute.name.startsWith("$unsafe{")) {
i += "$unsafe".length() - 1;
outputPrevented = false;
return;
}
if (!attribute.hasValue) {
if (attribute.name.startsWith("$unsafe{")) {
i += "$unsafe".length() - 1;
outputPrevented = false;
return;
}

if (attribute.name.startsWith("${")) {
outputPrevented = false;
return;
if (attribute.name.startsWith("${")) {
outputPrevented = false;
return;
}
}

currentHtmlTag.attributes.add(attribute);
Expand Down Expand Up @@ -853,10 +855,12 @@ private String parseHtmlTagName(int index) {
private HtmlAttribute parseHtmlAttribute() {
int nameEndIndex = -1;
char quotes = 0;
boolean hasValue = false;
for (int j = i; j < endIndex; ++j) {
char c = templateCode.charAt(j);

if (c == '=') {
hasValue = true;
quotes = parseHtmlAttributeQuotes(j + 1);
}

Expand All @@ -873,7 +877,7 @@ private HtmlAttribute parseHtmlAttribute() {
return null;
}

return new HtmlAttribute(templateCode.substring(i, nameEndIndex), quotes, i, isHtmlAttributeSingleOutput(nameEndIndex, quotes));
return new HtmlAttribute(templateCode.substring(i, nameEndIndex), quotes, i, isHtmlAttributeSingleOutput(nameEndIndex, quotes), hasValue);
}

private char parseHtmlAttributeQuotes(int index) {
Expand Down Expand Up @@ -1208,18 +1212,20 @@ public static class HtmlAttribute implements gg.jte.html.HtmlAttribute {
public final int startIndex;
public final boolean containsSingleOutput;
public final boolean bool;
public final boolean hasValue;
public String value;
public String variableName;

public int quoteCount;
public int valueStartIndex;

private HtmlAttribute(String name, char quotes, int startIndex, boolean containsSingleOutput) {
private HtmlAttribute(String name, char quotes, int startIndex, boolean containsSingleOutput, boolean hasValue) {
this.name = name;
this.quotes = quotes;
this.startIndex = startIndex;
this.containsSingleOutput = containsSingleOutput;
this.bool = BOOLEAN_HTML_ATTRIBUTES.contains(name);
this.hasValue = hasValue;
}

@Override
Expand Down

0 comments on commit e8fca09

Please sign in to comment.