Skip to content

Commit 079b1e3

Browse files
authored
Merge pull request #24 from anonyein/origin
Origin
2 parents 391a59e + cc90f72 commit 079b1e3

File tree

7 files changed

+57
-7
lines changed

7 files changed

+57
-7
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ updates:
1111
update-types: ["version-update:semver-major"]
1212
- dependency-name: "org.eclipse.jetty:jetty-servlet"
1313
update-types: ["version-update:semver-major"]
14+
# Et tu, junit? Keep us on 5, as 6 has min JDK17 - https://docs.junit.org/6.0.0-RC3/release-notes/#release-notes-6.0.0-M1
15+
- dependency-name: "org.junit.jupiter:junit-jupiter"
16+
update-types: ["version-update:semver-major"]
1417

1518
- package-ecosystem: github-actions
1619
directory: /

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020
distribution: 'temurin'
2121
cache: 'maven'
2222
- name: CodeQL Initialization
23-
uses: github/codeql-action/init@v3
23+
uses: github/codeql-action/init@v4
2424
with:
2525
languages: java
2626
queries: +security-and-quality
2727
- name: Autobuild
28-
uses: github/codeql-action/autobuild@v3
28+
uses: github/codeql-action/autobuild@v4
2929
- name: CodeQL Analysis
30-
uses: github/codeql-action/analyze@v3
30+
uses: github/codeql-action/analyze@v4

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Null characters in the HTML body were not consistently removed; and in foreign content were not correctly replaced. [#2395](https://github.com/jhy/jsoup/issues/2395)
2626
* An IndexOutOfBoundsException could be thrown when parsing a body fragment with crafted input. Now logged as a parse error. [#2397](https://github.com/jhy/jsoup/issues/2397), [#2406](https://github.com/jhy/jsoup/issues/2406)
2727
* When using StructuralEvaluators (e.g., a `parent child` selector) across many retained threads, their memoized results could also be retained, increasing memory use. These results are now cleared immediately after use, reducing overall memory consumption. [#2411](https://github.com/jhy/jsoup/issues/2411)
28+
* Custom tags marked as `Tag.Void` now parse and serialize like the built-in void elements: they no longer consume following content, and the XML serializer emits the expected self-closing form. [#2425](https://github.com/jhy/jsoup/issues/2425)
2829

2930
### Internal Changes
3031
* Deprecated internal helper `org.jsoup.internal.Functions` (for removal in v1.23.1). This was previously used to support older Android API levels without full `java.util.function` coverage; jsoup now requires core library desugaring so this indirection is no longer necessary. [#2412](https://github.com/jhy/jsoup/pull/2412)

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<plugin>
6767
<groupId>org.codehaus.mojo</groupId>
6868
<artifactId>animal-sniffer-maven-plugin</artifactId>
69-
<version>1.24</version>
69+
<version>1.26</version>
7070
<executions>
7171
<execution>
7272
<id>api-java8</id>
@@ -275,7 +275,7 @@
275275
<!-- API version compat check - https://siom79.github.io/japicmp/ -->
276276
<groupId>com.github.siom79.japicmp</groupId>
277277
<artifactId>japicmp-maven-plugin</artifactId>
278-
<version>0.23.1</version>
278+
<version>0.24.2</version>
279279
<configuration>
280280
<!-- hard code previous version; can't detect when running stateless on build server -->
281281
<oldVersion>
@@ -501,7 +501,7 @@
501501
<dependency>
502502
<groupId>org.junit.jupiter</groupId>
503503
<artifactId>junit-jupiter</artifactId>
504-
<version>5.13.4</version>
504+
<version>5.14.0</version>
505505
<scope>test</scope>
506506
</dependency>
507507

src/main/java/org/jsoup/parser/HtmlTreeBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ Element insertElementFor(final Token.StartTag startTag) {
332332
if (startTag.isSelfClosing()) {
333333
Tag tag = el.tag();
334334
tag.setSeenSelfClose(); // can infer output if in xml syntax
335-
if (tag.isKnownTag() && (tag.isEmpty() || tag.isSelfClosing())) {
335+
if (tag.isEmpty()) {
336+
// treated as empty below; nothing further
337+
} else if (tag.isKnownTag() && tag.isSelfClosing()) {
336338
// ok, allow it. effectively a pop, but fiddles with the state. handles empty style, title etc which would otherwise leave us in data state
337339
tokeniser.transition(TokeniserState.Data); // handles <script />, otherwise needs breakout steps from script data
338340
tokeniser.emit(emptyEnd.reset().name(el.tagName())); // ensure we get out of whatever state we are in. emitted for yielded processing
@@ -342,6 +344,10 @@ Element insertElementFor(final Token.StartTag startTag) {
342344
}
343345
}
344346

347+
if (el.tag().isEmpty()) {
348+
pop(); // custom void tags behave like built-in voids (no children, not left on the stack); known empty go via insertEmpty
349+
}
350+
345351
return el;
346352
}
347353

src/test/java/org/jsoup/integration/TestServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ private static void addHttpsConnector(File keystoreFile, Server server) {
177177
server,
178178
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
179179
new HttpConnectionFactory(httpsConfig));
180+
sslConnector.setHost(Localhost);
180181
server.addConnector(sslConnector);
181182
}
182183

src/test/java/org/jsoup/parser/HtmlParserTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,45 @@ static void assertErrorsDoNotContain(String msg, ParseErrorList errors) {
21062106
assertEquals("<div /><custom /><custom>Foo</custom>", TextUtil.stripNewlines(doc.body().html()));
21072107
}
21082108

2109+
@Test void customVoidTagsBehaveLikeHtmlVoids() {
2110+
Parser parser = Parser.htmlParser().setTrackErrors(10).tagSet(TagSet.Html());
2111+
TagSet tags = parser.tagSet();
2112+
tags.valueOf("voidtag", Parser.NamespaceHtml).set(Tag.Void);
2113+
2114+
String html = "<p><voidtag>Hello World</p>";
2115+
Document doc = Jsoup.parse(html, parser);
2116+
assertEquals(0, parser.getErrors().size());
2117+
2118+
doc.outputSettings().syntax(Document.OutputSettings.Syntax.html);
2119+
String emittedHtml = TextUtil.stripNewlines(doc.body().html());
2120+
assertEquals("<p><voidtag>Hello World</p>", emittedHtml);
2121+
assertEquals("Hello World", doc.body().text());
2122+
2123+
doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
2124+
assertEquals("<p><voidtag />Hello World</p>", TextUtil.stripNewlines(doc.body().html()));
2125+
}
2126+
2127+
@Test void customSelfClosingVoidTagsRoundTrip() {
2128+
Parser parser = Parser.htmlParser().setTrackErrors(10).tagSet(TagSet.Html());
2129+
TagSet tags = parser.tagSet();
2130+
tags.valueOf("selfclosingvoidtag", Parser.NamespaceHtml).set(Tag.Void).set(Tag.SelfClose);
2131+
2132+
String html = "<p><selfclosingvoidtag />Hello World</p>";
2133+
Document doc = Jsoup.parse(html, parser);
2134+
assertEquals(0, parser.getErrors().size());
2135+
2136+
doc.outputSettings().syntax(Document.OutputSettings.Syntax.html);
2137+
String emittedHtml = TextUtil.stripNewlines(doc.body().html());
2138+
assertEquals("<p><selfclosingvoidtag>Hello World</p>", emittedHtml);
2139+
2140+
Document reparsed = Jsoup.parse(emittedHtml, parser);
2141+
reparsed.outputSettings().syntax(Document.OutputSettings.Syntax.html);
2142+
assertEquals(emittedHtml, TextUtil.stripNewlines(reparsed.body().html()));
2143+
2144+
doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
2145+
assertEquals("<p><selfclosingvoidtag />Hello World</p>", TextUtil.stripNewlines(doc.body().html()));
2146+
}
2147+
21092148
@Test void svgScriptParsedAsScriptData() {
21102149
// https://github.com/jhy/jsoup/issues/2320
21112150
String html = "<svg><script>a < b</script></svg>";

0 commit comments

Comments
 (0)