Skip to content

Commit

Permalink
fix!: bump Jsoup version (#12046) (#12081)
Browse files Browse the repository at this point in the history
This fix introduces a potential backward incompatibility for the users who uses JSoup dependency explicitly in their code.For such users either the JSoup dependency in their project should be declared explicitly (with an older version) or the code needs to be updated to use new JSoup API.
  • Loading branch information
Denis authored Oct 25, 2021
1 parent ed16b62 commit cae023f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.frontend.installer.NodeInstaller;
import org.apache.maven.model.Build;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -52,6 +50,8 @@

import com.vaadin.flow.plugin.TestUtils;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.frontend.installer.NodeInstaller;

import elemental.json.Json;
import elemental.json.JsonObject;
Expand Down Expand Up @@ -205,7 +205,7 @@ public void should_UpdateMainJsFile() throws Exception {

List<String> expectedLines = new ArrayList<>(Arrays.asList(
"const div = document.createElement('div');",
"div.innerHTML = '<custom-style><style include=\"lumo-color lumo-typography\"></style></custom-style>';",
"div.innerHTML = '<custom-style> <style include=\"lumo-color lumo-typography\"></style></custom-style>';",
"document.head.insertBefore(div.firstElementChild, document.head.firstChild);",
"document.documentElement.setAttribute('theme', 'dark');"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasElement;
import com.vaadin.flow.component.UI;
Expand Down Expand Up @@ -58,10 +63,6 @@
import com.vaadin.flow.shared.ui.LoadMode;
import com.vaadin.flow.theme.AbstractTheme;
import com.vaadin.flow.theme.ThemeDefinition;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;

import elemental.json.Json;
import elemental.json.JsonObject;
Expand Down Expand Up @@ -374,12 +375,13 @@ private static JsonObject createHeaderInlineScript(AbstractTheme theme) {

private static StringBuilder createHeaderInjectionCall(String content) {
StringBuilder inlineContent = new StringBuilder();
Document document = Jsoup.parse(content, "", Parser.xmlParser());
Document document = Jsoup.parse(content.replaceAll("\\R+", " ").trim(),
"", Parser.xmlParser());
for (Element element : document.children()) {
String tagName = element.tagName();
inlineContent.append("_inlineHeader('");
inlineContent.append(tagName).append("',");
inlineContent.append(makeJsString(element.html()));
inlineContent.append(makeJsString(element.html().trim()));
inlineContent.append(");\n");
}
return inlineContent;
Expand Down Expand Up @@ -463,26 +465,26 @@ public static Optional<Class<?>> resolvePageConfigurationHolder(UI ui,
// found" target
return resolveRouteNotFoundNavigationTarget(
ui.getSession().getService().getContext())
.map(errorNavigationTarget -> {
/*
* {@code resolveTopParentLayout} is theoretically the
* correct way to get the parent layout. But in fact it does
* work for non route targets.
*/
List<Class<? extends RouterLayout>> layouts = RouteUtil
.getParentLayoutsForNonRouteTarget(
errorNavigationTarget);
if (layouts.isEmpty()) {
return errorNavigationTarget;
} else {
return layouts.get(layouts.size() - 1);
}
});
.map(errorNavigationTarget -> {
/*
* {@code resolveTopParentLayout} is theoretically
* the correct way to get the parent layout. But in
* fact it does work for non route targets.
*/
List<Class<? extends RouterLayout>> layouts = RouteUtil
.getParentLayoutsForNonRouteTarget(
errorNavigationTarget);
if (layouts.isEmpty()) {
return errorNavigationTarget;
} else {
return layouts.get(layouts.size() - 1);
}
});
}

/*
* NOTE: this code doesn't belong in this class, but is just
* c/p from Router to avoid adding new API to 2.1.
* NOTE: this code doesn't belong in this class, but is just c/p from Router
* to avoid adding new API to 2.1.
*/
private static Optional<Class<? extends Component>> resolveRouteNotFoundNavigationTarget(
VaadinContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vaadin.flow.server;

import javax.servlet.http.HttpServletRequest;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -83,7 +84,7 @@ public class BootstrapHandlerTest {
+ "customStyle.innerHTML= content;\n"
+ "var firstScript=document.head.querySelector('script');\n"
+ "document.head.insertBefore(customStyle,firstScript);\n" + "}\n"
+ "_inlineHeader('custom-style','<style include=\"lumo-typography\"></style>');\n"
+ "_inlineHeader('custom-style','<style include=\"lumo-typography\"> </style>');\n"
+ "var script = document.getElementById('_theme-header-injection');"
+ "if ( script ) { document.head.removeChild(script);}\n"
+ "</script>";
Expand Down Expand Up @@ -321,7 +322,7 @@ public String getThemeUrl() {
@Override
public List<String> getHeaderInlineContents() {
return Arrays.asList(
"<custom-style><style include=\"lumo-typography\"></style></custom-style>");
"<custom-style>\n<style include=\"lumo-typography\">\n </style>\r\n</custom-style>");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String getThemeUrl() {

@Override
public List<String> getHeaderInlineContents() {
return Collections.singletonList("<custom-style>\n <style>\n html {\n"
+ " font-size: 20px;\n color:red; }\n <style>\n </custom-style>");
return Collections.singletonList("<custom-style> <style> html {"
+ " font-size: 20px; color:red; } </style> </custom-style>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public String getThemeUrl() {

@Override
public List<String> getHeaderInlineContents() {
return Collections.singletonList("<custom-style>\n"
+ " <style include=\"lumo-color lumo-typography\"></style>\n"
return Collections.singletonList("<custom-style>"
+ " <style include=\"lumo-color lumo-typography\"></style>"
+ "</custom-style>");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public String getThemeUrl() {

@Override
public List<String> getHeaderInlineContents() {
return Collections.singletonList("<custom-style>\n"
+ " <style include=\"material-color-light material-typography\"></style>\n"
return Collections.singletonList("<custom-style>"
+ " <style include=\"material-color-light material-typography\"></style>"
+ "</custom-style>");
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<flow.dev.dependencies.file>devDependencies.json</flow.dev.dependencies.file>

<!-- Used in OSGi manifests -->
<jsoup.version>1.12.1</jsoup.version>
<jsoup.version>1.14.3</jsoup.version>
<!-- Note that this should be kept in sync with the class Constants -->
<atmosphere.runtime.version>2.4.30.slf4jvaadin1</atmosphere.runtime.version>

Expand Down

0 comments on commit cae023f

Please sign in to comment.