Skip to content

Commit a1be531

Browse files
committed
inserted tags are in lower case (at least if the option for uppercase tag names is not set)
1 parent b31e17d commit a1be531

2 files changed

Lines changed: 27 additions & 24 deletions

File tree

src/main/java/org/htmlunit/cyberneko/HTMLScanner.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ else if ("plaintext".equalsIgnoreCase(fFragmentSpecialScannerTag_)) {
981981
*/
982982
public boolean scanDocument(final boolean complete) throws XNIException, IOException {
983983
do {
984-
int scan = fScanner.scan(complete);
984+
final int scan = fScanner.scan(complete);
985985
if (SCAN_FALSE == scan) {
986986
return false;
987987
}
@@ -1240,7 +1240,7 @@ protected int scanDoctype() throws IOException {
12401240
}
12411241
else if (fCurrentEntity.skip("SYSTEM")) {
12421242
fCurrentEntity.skipSpaces();
1243-
int scanLiteral = scanLiteral();
1243+
final int scanLiteral = scanLiteral();
12441244
if (SCAN_EOF == scanLiteral) {
12451245
return SCAN_EOF;
12461246
}
@@ -1896,7 +1896,7 @@ String nextContent(final int len) throws IOException {
18961896
}
18971897

18981898
// Reads a single character, preserving the old buffer content
1899-
private int readPreservingBufferContent() throws IOException {
1899+
int readPreservingBufferContent() throws IOException {
19001900
if (DEBUG_BUFFER) {
19011901
debugBufferIfNeeded("(readPreserving: ");
19021902
}
@@ -2022,7 +2022,7 @@ int getCharacterOffset() {
20222022

20232023
// Returns true if the specified text is present (case-insensitive) and is skipped.
20242024
// for performance reasons you have to provide the specified text in uppercase
2025-
private boolean skip(final String expectedInUpperCase) throws IOException {
2025+
boolean skip(final String expectedInUpperCase) throws IOException {
20262026
final int length = expectedInUpperCase != null ? expectedInUpperCase.length() : 0;
20272027
for (int i = 0; i < length; i++) {
20282028
if (offset_ == length_) {
@@ -2043,7 +2043,7 @@ private boolean skip(final String expectedInUpperCase) throws IOException {
20432043
}
20442044

20452045
// Skips markup.
2046-
private boolean skipMarkup(final boolean balance) throws IOException {
2046+
boolean skipMarkup(final boolean balance) throws IOException {
20472047
if (DEBUG_BUFFER) {
20482048
debugBufferIfNeeded("(skipMarkup: ");
20492049
}
@@ -2097,7 +2097,7 @@ else if (c == '\r' || c == '\n') {
20972097
}
20982098

20992099
// Skips whitespace.
2100-
private boolean skipSpaces() throws IOException {
2100+
boolean skipSpaces() throws IOException {
21012101
if (DEBUG_BUFFER) {
21022102
debugBufferIfNeeded("(skipSpaces: ");
21032103
}
@@ -2133,7 +2133,7 @@ else if (Character.isWhitespace(c)) {
21332133
}
21342134

21352135
// Skips newlines and returns the number of newlines skipped.
2136-
private int skipNewlines() throws IOException {
2136+
int skipNewlines() throws IOException {
21372137
if (DEBUG_BUFFER) {
21382138
debugBufferIfNeeded("(skipNewlines: ");
21392139
}
@@ -2388,7 +2388,7 @@ else if (ename != null) {
23882388
}
23892389
if (fInsertDoctype_) {
23902390
fDocumentHandler.doctypeDecl(
2391-
NAMES_LOWERCASE == fNamesElems ? "html" : "HTML",
2391+
NAMES_UPPERCASE == fNamesElems ? "HTML" : "html",
23922392
fDoctypePubid,
23932393
fDoctypeSysid,
23942394
synthesizedAugs());
@@ -2449,9 +2449,9 @@ private void scanUntilEndTag(final String tagName) throws IOException {
24492449
}
24502450
if (c == '<') {
24512451
final String next = fCurrentEntity.nextContent(lengthToScan) + " ";
2452-
if (next.length() >= lengthToScan
2452+
if (next.length() >= lengthToScan
24532453
&& end.equalsIgnoreCase(next.substring(0, end.length()))
2454-
&& ('>' == next.charAt(lengthToScan - 1)
2454+
&& ('>' == next.charAt(lengthToScan - 1)
24552455
|| Character.isWhitespace(next.charAt(lengthToScan - 1)))) {
24562456
fCurrentEntity.rewind();
24572457
break;
@@ -2864,7 +2864,6 @@ else if (c == '>') {
28642864
return SCAN_EOF;
28652865
}
28662866

2867-
28682867
final String version = attributes_.getValue("version");
28692868
final String encoding = attributes_.getValue("encoding");
28702869
final String standalone = attributes_.getValue("standalone");
@@ -3190,7 +3189,8 @@ protected int scanAttribute(final XMLAttributesImpl attributes, final boolean[]
31903189
plainAttribValue.toString(), true);
31913190
}
31923191
else {
3193-
if (SCAN_EOF == scanAttributeQuotedValue(c, fCurrentEntity, attribValue, null, fNormalizeAttributes_)) {
3192+
if (SCAN_EOF == scanAttributeQuotedValue(c, fCurrentEntity,
3193+
attribValue, null, fNormalizeAttributes_)) {
31943194
return SCAN_EOF;
31953195
}
31963196

src/main/java/org/htmlunit/cyberneko/HTMLTagBalancer.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public void endDocument(final Augmentations augs) throws XNIException {
519519
fQName.setValues(null, body, body, null);
520520
callEndElement(fQName, synthesizedAugs());
521521

522-
final String ename = NAMES_UPPERCASE == fNamesElems ? "HTML": "html";
522+
final String ename = NAMES_UPPERCASE == fNamesElems ? "HTML" : "html";
523523
fQName.setValues(null, ename, ename, null);
524524
callEndElement(fQName, synthesizedAugs());
525525
}
@@ -660,7 +660,7 @@ public void startElement(final QName elem, XMLAttributes attrs, final Augmentati
660660

661661
if (!fTemplateFragment && fOpenedSelect) {
662662
if (elementCode == HTMLElements.SELECT) {
663-
final QName head = createQName("select");
663+
final QName head = createQName(fNamesElems == NAMES_UPPERCASE ? "SELECT" : "select");
664664
endElement(head, synthesizedAugs());
665665

666666
notifyDiscardedStartElement(elem, attrs, augs);
@@ -693,7 +693,7 @@ else if (!fOpenedSvg && elementCode == HTMLElements.FRAMESET) {
693693
}
694694
// create <head></head> if none was present
695695
if (!fSeenHeadElement) {
696-
final QName head = createQName("head");
696+
final QName head = createQName(fNamesElems == NAMES_UPPERCASE ? "HEAD" : "head");
697697
forceStartElement(head, new XMLAttributesImpl(), synthesizedAugs());
698698
endElement(head, synthesizedAugs());
699699
}
@@ -712,7 +712,7 @@ else if (!fOpenedSvg && elementCode == HTMLElements.FRAMESET) {
712712
else if (elementCode == HTMLElements.BODY) {
713713
// create <head></head> if none was present
714714
if (!fSeenHeadElement) {
715-
final QName head = createQName("head");
715+
final QName head = createQName(fNamesElems == NAMES_UPPERCASE ? "HEAD" : "head");
716716
forceStartElement(head, new XMLAttributesImpl(), synthesizedAugs());
717717
endElement(head, synthesizedAugs());
718718
}
@@ -749,7 +749,8 @@ else if (elementCode == HTMLElements.FORM) {
749749
|| info.element.code == HTMLElements.TABLE) {
750750
if (documentHandler_ != null) {
751751
callStartElement(elem, attrs, augs);
752-
callEndElement(createQName("form"), synthesizedAugs());
752+
callEndElement(createQName(fNamesElems == NAMES_UPPERCASE ? "FORM" : "form"),
753+
synthesizedAugs());
753754
}
754755
fOpenedForm = false;
755756
return;
@@ -782,7 +783,7 @@ else if (elementCode == HTMLElements.TABLE) {
782783
|| info.element.code == HTMLElements.TBODY
783784
|| info.element.code == HTMLElements.TFOOT
784785
|| info.element.code == HTMLElements.TABLE) {
785-
final QName table = createQName("table");
786+
final QName table = createQName(fNamesElems == NAMES_UPPERCASE ? "TABLE" : "table");
786787
endElement(table, synthesizedAugs());
787788
break;
788789
}
@@ -804,7 +805,8 @@ else if (fTemplateFragment
804805
// nothing, don't force/check parent for the direct template children
805806
}
806807
else if (!fSeenRootElement && !fDocumentFragment) {
807-
final String pname = preferedParent.name;
808+
final String pname = fNamesElems == NAMES_UPPERCASE
809+
? preferedParent.name : preferedParent.lowercaseName;
808810
if (fReportErrors) {
809811
final String ename = elem.getRawname();
810812
fErrorReporter.reportWarning("HTML2002", new Object[]{ename, pname});
@@ -822,7 +824,8 @@ else if (!fSeenRootElement && !fDocumentFragment) {
822824
if (preferedParent.code != HTMLElements.HEAD || (!fSeenBodyElement && !fDocumentFragment)) {
823825
final int depth = getParentDepth(element);
824826
if (depth == -1) { // no parent found
825-
final String pname = preferedParent.name;
827+
final String pname = fNamesElems == NAMES_UPPERCASE
828+
? preferedParent.name : preferedParent.lowercaseName;
826829
if (fReportErrors) {
827830
final String ename = elem.getRawname();
828831
fErrorReporter.reportWarning("HTML2004", new Object[]{ename, pname});
@@ -963,7 +966,7 @@ private boolean forceStartElement(final QName elem, final XMLAttributes attrs,
963966
return fElementStack.top > 0 && elem.equals(fElementStack.peek().qname);
964967
}
965968

966-
private QName createQName(String tagName) {
969+
private static QName createQName(final String tagName) {
967970
return new QName(null, tagName, tagName, NamespaceBinder.XHTML_1_0_URI);
968971
}
969972

@@ -987,7 +990,7 @@ public void emptyElement(final QName element, final XMLAttributes attrs,
987990
* Generates a missing <body> (which creates missing <head> when needed)
988991
*/
989992
private void forceStartBody() {
990-
final QName body = createQName("body");
993+
final QName body = createQName(fNamesElems == NAMES_UPPERCASE ? "BODY" : "body");
991994
if (fReportErrors) {
992995
fErrorReporter.reportWarning("HTML2006", new Object[]{body.getLocalpart()});
993996
}
@@ -1309,12 +1312,12 @@ protected final void callStartElement(final QName element, final XMLAttributes a
13091312
private void addBodyIfNeeded(final short element) {
13101313
if (!fDocumentFragment && !fSeenFramesetElement && element == HTMLElements.HTML) {
13111314
if (!fSeenHeadElement) {
1312-
final QName head = createQName("head");
1315+
final QName head = createQName(fNamesElems == NAMES_UPPERCASE ? "HEAD" : "head");
13131316
callStartElement(head, new XMLAttributesImpl(), synthesizedAugs());
13141317
callEndElement(head, synthesizedAugs());
13151318
}
13161319
if (!fSeenBodyElement) {
1317-
final QName body = createQName("body");
1320+
final QName body = createQName(fNamesElems == NAMES_UPPERCASE ? "BODY" : "body");
13181321
callStartElement(body, new XMLAttributesImpl(), synthesizedAugs());
13191322
callEndElement(body, synthesizedAugs());
13201323
}

0 commit comments

Comments
 (0)