From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- parser/html/javasrc/Tokenizer.java | 24 ++++++++++++++++++++++-- parser/html/javasrc/TreeBuilder.java | 23 +++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) (limited to 'parser/html/javasrc') diff --git a/parser/html/javasrc/Tokenizer.java b/parser/html/javasrc/Tokenizer.java index 0357cd0155..6d7c349155 100644 --- a/parser/html/javasrc/Tokenizer.java +++ b/parser/html/javasrc/Tokenizer.java @@ -511,6 +511,8 @@ public class Tokenizer implements Locator, Locator2 { private boolean shouldSuspend; + private boolean keepBuffer; + protected boolean confident; private int line; @@ -570,6 +572,7 @@ public class Tokenizer implements Locator, Locator2 { this.systemIdentifier = null; this.attributes = null; this.shouldSuspend = false; + this.keepBuffer = false; this.confident = false; this.line = 0; // CPPONLY: this.attributeLine = 0; @@ -632,6 +635,7 @@ public class Tokenizer implements Locator, Locator2 { // CPPONLY: this.attributes = tokenHandler.HasBuilder() ? new HtmlAttributes(mappingLangToXmlLang) : null; // CPPONLY: this.newAttributesEachTime = !tokenHandler.HasBuilder(); this.shouldSuspend = false; + this.keepBuffer = false; this.confident = false; this.line = 0; // CPPONLY: this.attributeLine = 0; @@ -653,6 +657,18 @@ public class Tokenizer implements Locator, Locator2 { // CPPONLY: return viewingXmlSource; // CPPONLY: } + public void setKeepBuffer(boolean keepBuffer) { + this.keepBuffer = keepBuffer; + } + + public boolean dropBufferIfLongerThan(int length) { + if (strBuf.length > length) { + strBuf = null; + return true; + } + return false; + } + // [NOCPP[ /** @@ -7225,7 +7241,9 @@ public class Tokenizer implements Locator, Locator2 { } public void end() throws SAXException { - strBuf = null; + if (!keepBuffer) { + strBuf = null; + } doctypeName = null; if (systemIdentifier != null) { Portability.releaseString(systemIdentifier); @@ -7415,7 +7433,9 @@ public class Tokenizer implements Locator, Locator2 { public void initializeWithoutStarting() throws SAXException { confident = false; - strBuf = null; + if (!keepBuffer) { + strBuf = null; + } line = 1; // CPPONLY: attributeLine = 1; // [NOCPP[ diff --git a/parser/html/javasrc/TreeBuilder.java b/parser/html/javasrc/TreeBuilder.java index f7b70ee0da..c190b7fd20 100644 --- a/parser/html/javasrc/TreeBuilder.java +++ b/parser/html/javasrc/TreeBuilder.java @@ -436,6 +436,8 @@ public abstract class TreeBuilder implements TokenHandler, private boolean allowDeclarativeShadowRoots = false; + private boolean keepBuffer = false; + // [NOCPP[ private boolean reportingDoctype = true; @@ -577,6 +579,18 @@ public abstract class TreeBuilder implements TokenHandler, // ]NOCPP] + public void setKeepBuffer(boolean keepBuffer) { + this.keepBuffer = keepBuffer; + } + + public boolean dropBufferIfLongerThan(int length) { + if (charBuffer.length > length) { + charBuffer = null; + return true; + } + return false; + } + @SuppressWarnings("unchecked") public final void startTokenization(Tokenizer self) throws SAXException { tokenizer = self; stackNodes = new StackNode[64]; @@ -598,7 +612,9 @@ public abstract class TreeBuilder implements TokenHandler, // ]NOCPP] start(fragment); charBufferLen = 0; - charBuffer = null; + if (!keepBuffer) { + charBuffer = null; + } framesetOk = true; if (fragment) { T elt; @@ -1451,7 +1467,10 @@ public abstract class TreeBuilder implements TokenHandler, // [NOCPP[ idLocations.clear(); // ]NOCPP] - charBuffer = null; + + if (!keepBuffer) { + charBuffer = null; + } end(); } -- cgit v1.2.3