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 CDATA early closing feature flag #126

Open
wants to merge 1 commit into
base: 3_11_3
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/main/java/org/htmlunit/cyberneko/HTMLScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.URL;
import java.util.Locale;

import org.htmlunit.cyberneko.HTMLElements.Element;
import org.htmlunit.cyberneko.io.PlaybackInputStream;
import org.htmlunit.cyberneko.util.MiniStack;
import org.htmlunit.cyberneko.xerces.util.EncodingMap;
Expand Down Expand Up @@ -59,6 +60,7 @@
* <li>http://cyberneko.org/html/features/scanner/style/strip-comment-delims
* <li>http://cyberneko.org/html/features/scanner/ignore-specified-charset
* <li>http://cyberneko.org/html/features/scanner/cdata-sections
* <li>http://cyberneko.org/html/features/scanner/cdata-early-closing
* <li>http://cyberneko.org/html/features/override-doctype
* <li>http://cyberneko.org/html/features/insert-doctype
* <li>http://cyberneko.org/html/features/parse-noscript-content
Expand Down Expand Up @@ -165,6 +167,9 @@ public class HTMLScanner implements XMLDocumentScanner, XMLLocator, HTMLComponen
/** Scan CDATA sections. */
public static final String CDATA_SECTIONS = "http://cyberneko.org/html/features/scanner/cdata-sections";

/** '>' closes the cdata section (see html spec) */
public static final String CDATA_EARLY_CLOSING = "http://cyberneko.org/html/features/scanner/cdata-early-closing";

/** Override doctype declaration public and system identifiers. */
public static final String OVERRIDE_DOCTYPE = "http://cyberneko.org/html/features/override-doctype";

Expand Down Expand Up @@ -193,6 +198,7 @@ public class HTMLScanner implements XMLDocumentScanner, XMLLocator, HTMLComponen
STYLE_STRIP_COMMENT_DELIMS,
IGNORE_SPECIFIED_CHARSET,
CDATA_SECTIONS,
CDATA_EARLY_CLOSING,
OVERRIDE_DOCTYPE,
INSERT_DOCTYPE,
NORMALIZE_ATTRIBUTES,
Expand All @@ -210,6 +216,7 @@ public class HTMLScanner implements XMLDocumentScanner, XMLLocator, HTMLComponen
Boolean.FALSE,
Boolean.FALSE,
Boolean.FALSE,
Boolean.TRUE,
Boolean.FALSE,
Boolean.FALSE,
Boolean.FALSE,
Expand Down Expand Up @@ -336,6 +343,9 @@ public class HTMLScanner implements XMLDocumentScanner, XMLLocator, HTMLComponen
/** CDATA sections. */
boolean fCDATASections_;

/** CDATA early closing. */
boolean fCDATAEarlyClosing_;

/** Override doctype declaration public and system identifiers. */
private boolean fOverrideDoctype_;

Expand Down Expand Up @@ -676,6 +686,7 @@ public void reset(final XMLComponentManager manager) throws XMLConfigurationExce
fStyleStripCommentDelims_ = manager.getFeature(STYLE_STRIP_COMMENT_DELIMS);
fIgnoreSpecifiedCharset_ = manager.getFeature(IGNORE_SPECIFIED_CHARSET);
fCDATASections_ = manager.getFeature(CDATA_SECTIONS);
fCDATAEarlyClosing_ = manager.getFeature(CDATA_EARLY_CLOSING);
fOverrideDoctype_ = manager.getFeature(OVERRIDE_DOCTYPE);
fInsertDoctype_ = manager.getFeature(INSERT_DOCTYPE);
fNormalizeAttributes_ = manager.getFeature(NORMALIZE_ATTRIBUTES);
Expand Down Expand Up @@ -2655,7 +2666,7 @@ protected boolean scanCDataContent(final XMLString xmlString) throws IOException
}
break;
}
else if (c == '>') {
else if (fCDATAEarlyClosing_&& c == '>') {
// don't add the ]] to the buffer
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>P1<![CDATA[<b><span>]]>
<p>P2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(HTML
(head
)head
(BODY
(p
"P1
#[CDATA[<b><span>]]
"\n
)p
(p
"P2
)p
)BODY
)HTML
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(HTML
(HEAD
)HEAD
(BODY
(P
"P1
#[CDATA[<b><span>]]
"\n
)P
(P
"P2
)P
)BODY
)HTML
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(p
"P1
#[CDATA[<b><span>]]
"\n
)p
(p
"P2
)p
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<HTML><head></head><BODY><p>P1<!--[CDATA[<b><span>]]-->
</p><p>P2</p></BODY></HTML>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feature http://cyberneko.org/html/features/scanner/cdata-early-closing false