Skip to content

Commit

Permalink
support early closing of cdata sections
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Dec 23, 2023
1 parent b3feeca commit 49a31c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/main/java/org/htmlunit/cyberneko/HTMLScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2271,9 +2271,7 @@ protected void scanCDATA() throws IOException {
fStringBuffer.append("[CDATA[");
}
final boolean eof = scanCDataContent(fStringBuffer);
if (!fCDATASections_) {
fStringBuffer.append("]]");
}

if (fDocumentHandler != null && fElementCount >= fElementDepth) {
fEndLineNumber = fCurrentEntity.getLineNumber();
fEndColumnNumber = fCurrentEntity.getColumnNumber();
Expand Down Expand Up @@ -2453,7 +2451,7 @@ protected boolean scanCDataContent(final XMLString xmlString) throws IOException
if (fReportErrors_) {
fErrorReporter.reportError("HTML1007", null);
}
return true;
break;
}

if (c == ']') {
Expand Down Expand Up @@ -2489,6 +2487,10 @@ protected boolean scanCDataContent(final XMLString xmlString) throws IOException
}
break;
}
else if (c == '>') {
// don't add the ]] to the buffer
return false;
}
else if (c == '\n' || c == '\r') {
fCurrentEntity.rewind();
final int newlines = skipNewlines();
Expand All @@ -2500,6 +2502,9 @@ else if (c == '\n' || c == '\r') {
appendChar(xmlString, c, null);
}

if (!fCDATASections_) {
fStringBuffer.append("]]");
}
return c == -1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<p>P1<![CDATA[<h1>Header</h1>]]>
<p>P1<![CDATA[Header < &gt;]]>
<p>P2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(BODY
(p
"P1
#[CDATA[<h1>Header</h1>]]
#[CDATA[Header < &gt;]]
"\n
)p
(p
Expand Down

0 comments on commit 49a31c0

Please sign in to comment.