Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inAttribute and change parameter order #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/org/owasp/html/HtmlEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,7 @@ public static int appendDecodedEntity(
* @param offset the position of the sequence to decode in {@code html}.
* @param limit the last position that could be part of the sequence to decode
* in {@code html}.
* @param inAttribute is html in an attribute value?
* @param sb string builder to append to.
* @return The offset after the end of the decoded sequence in {@code html}.
*/
Expand Down Expand Up @@ -2439,7 +2440,7 @@ public static int appendDecodedEntity(
char nameChar = html.charAt(i);
t = t.lookup(nameChar);
if (t == null) { break; }
if (t.isTerminal() && mayComplete(inAttribute, html, i, limit)) {
if (t.isTerminal() && mayComplete(html, inAttribute, i, limit)) {
longestDecode = t;
tail = i + 1;
}
Expand All @@ -2452,7 +2453,7 @@ public static int appendDecodedEntity(
if ('Z' >= nameChar && nameChar >= 'A') { nameChar |= 32; }
t = t.lookup(nameChar);
if (t == null) { break; }
if (t.isTerminal() && mayComplete(inAttribute, html, i, limit)) {
if (t.isTerminal() && mayComplete(html, inAttribute, i, limit)) {
longestDecode = t;
tail = i + 1;
}
Expand Down Expand Up @@ -2480,7 +2481,7 @@ private static boolean isHtmlIdContinueChar(char ch) {
}

/** True if the character at i in html may complete a named character reference */
private static boolean mayComplete(boolean inAttribute, String html, int i, int limit) {
private static boolean mayComplete(String html, boolean inAttribute, int i, int limit) {
if (inAttribute && html.charAt(i) != ';' && i + 1 < limit) {
// See if the next character blocks treating this as a full match.
// This avoids problems like "&para" being treated as a decoding in
Expand Down