Skip to content
Merged
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
10 changes: 6 additions & 4 deletions owasp-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
<vulnerabilityName>CVE-2022-29546</vulnerabilityName>
</suppress>
<suppress>
<notes><![CDATA[
xalan is used by batik
]]></notes>
<packageUrl regex="true">^pkg:maven/xerces/xercesImpl@.*$</packageUrl>
<vulnerabilityName>CVE-2017-10355</vulnerabilityName>
</suppress>
<suppress>
<notes><![CDATA[
xalan is used by batik
]]></notes>
<packageUrl regex="true">^pkg:maven/xalan/xalan@.*$</packageUrl>
<vulnerabilityName>CVE-2022-34169</vulnerabilityName>
</suppress>
<suppress>
<packageUrl regex="true">^pkg:maven/xalan/serializer@.*$</packageUrl>
<vulnerabilityName>CVE-2022-34169</vulnerabilityName>
</suppress>
<suppress>
<packageUrl regex="true">^pkg:maven/.*jetty.io.9\.4\.48\.v20220622.*$</packageUrl>
<vulnerabilityName>CVE-2022-2191</vulnerabilityName>
</suppress>
</suppressions>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<htmlunitcssparser.version>1.12.0</htmlunitcssparser.version>
<htmlunitneko.version>2.64.0</htmlunitneko.version>
<htmlunitcorejs.version>2.64.0</htmlunitcorejs.version>
<htmlunitxpath.version>1.0.0-SNAPSHOT</htmlunitxpath.version>
<htmlunitxpath.version>2.65.0-SNAPSHOT</htmlunitxpath.version>

<httpcomponents.version>4.5.13</httpcomponents.version>
<jetty.version>9.4.49.v20220914</jetty.version>
Expand Down
7 changes: 6 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@

<body>
<release version="2.65.0" date="xxxx, 2022" description="Chrome/Edge 105, Firefox 104">
<action type="remove" dev="rbri">
com.gargoylesoftware.htmlunit.util.TextUtils removed.
</action>
<action type="update" dev="rbri">
Switch from xalan to htmlunit-xpath.
</action>
<action type="update" dev="rbri">
Upgrade Jetty to 9.4.49.v20220914.
</action>
<action type="add" dev="rbri" issue="501">
Introducing a PrintHandler configurable at the WebClient. You can provide your
own Window.print() implementations if required.
</action>

<action type="fix" dev="rbri">
A bug in one faq sample code that might result in wrong encoding is fixed.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import com.gargoylesoftware.htmlunit.util.MimeType;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.TextUtils;

/**
* A fake {@link WebConnection} designed to mock out the actual HTTP connections.
Expand Down Expand Up @@ -103,7 +102,7 @@ else if (stringContent_ == null) {
content = new byte[] {};
}
else {
content = TextUtils.stringToByteArray(stringContent_, charset_);
content = stringContent_.getBytes(charset_);
}
return new WebResponseData(content, statusCode_, statusMessage_, headers_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.http.HttpStatus;

import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.TextUtils;
import com.gargoylesoftware.htmlunit.util.StringUtils;

/**
* A simple WebResponse created from a string. Content is assumed to be of type <tt>text/html</tt>.
Expand Down Expand Up @@ -68,7 +68,7 @@ public StringWebResponse(final String content, final Charset charset, final URL
* @return a simple <tt>WebResponseData</tt> with defaults specified
*/
private static WebResponseData getWebResponseData(final String contentString, final Charset charset) {
final byte[] content = TextUtils.stringToByteArray(contentString, charset);
final byte[] content = StringUtils.toByteArray(contentString, charset);
final List<NameValuePair> compiledHeaders = new ArrayList<>();
compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, "text/html; charset=" + charset));
return new WebResponseData(content, HttpStatus.SC_OK, "OK", compiledHeaders);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gargoylesoftware/htmlunit/WebClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
import com.gargoylesoftware.htmlunit.util.Cookie;
import com.gargoylesoftware.htmlunit.util.MimeType;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.TextUtils;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
import com.gargoylesoftware.htmlunit.webstart.WebStartHandler;
import com.shapesecurity.salvation2.Policy;
Expand Down Expand Up @@ -1424,7 +1423,8 @@ private WebResponse makeWebResponseForFileUrl(final WebRequest webRequest) throw
compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, MimeType.TEXT_HTML));
final WebResponseData responseData =
new WebResponseData(
TextUtils.stringToByteArray("File: " + file.getAbsolutePath(), UTF_8),
com.gargoylesoftware.htmlunit.util.StringUtils
.toByteArray("File: " + file.getAbsolutePath(), UTF_8),
404, "Not Found", compiledHeaders);
return new WebResponse(responseData, webRequest, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;

import com.gargoylesoftware.htmlunit.util.TextUtils;
import org.apache.commons.io.IOUtils;

/**
* A URLConnection for supporting JavaScript URLs.
Expand Down Expand Up @@ -56,7 +57,7 @@ public void connect() {
*/
@Override
public InputStream getInputStream() {
return TextUtils.toInputStream(content_);
return IOUtils.toInputStream(content_, StandardCharsets.ISO_8859_1);
}

}
16 changes: 16 additions & 0 deletions src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.gargoylesoftware.htmlunit.util;

import java.nio.charset.Charset;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -385,4 +386,19 @@ public static String cssDeCamelize(final String string) {
}
return builder.toString();
}

/**
* Converts a string into a byte array using the specified encoding.
*
* @param charset the charset
* @param content the string to convert
* @return the String as a byte[]; if the specified encoding is not supported an empty byte[] will be returned
*/
public static byte[] toByteArray(final String content, final Charset charset) {
if (content == null || content.isEmpty()) {
return new byte[0];
}

return content.getBytes(charset);
}
}
89 changes: 0 additions & 89 deletions src/main/java/com/gargoylesoftware/htmlunit/util/TextUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.junit.BrowserRunner;
import com.gargoylesoftware.htmlunit.util.MimeType;
import com.gargoylesoftware.htmlunit.util.TextUtils;
import com.gargoylesoftware.htmlunit.util.StringUtils;

/**
* Tests for {@link DomText}.
Expand Down Expand Up @@ -161,7 +161,7 @@ public void asXml() throws Exception {
final WebClient client = getWebClient();
final MockWebConnection webConnection = new MockWebConnection();

webConnection.setDefaultResponse(TextUtils.stringToByteArray(html, UTF_8), 200, "OK", MimeType.TEXT_HTML);
webConnection.setDefaultResponse(StringUtils.toByteArray(html, UTF_8), 200, "OK", MimeType.TEXT_HTML);
client.setWebConnection(webConnection);

final HtmlPage page = client.getPage(URL_FIRST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -33,6 +34,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -59,7 +61,7 @@
import com.gargoylesoftware.htmlunit.util.Cookie;
import com.gargoylesoftware.htmlunit.util.MimeType;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.TextUtils;
import com.gargoylesoftware.htmlunit.util.StringUtils;

/**
* Tests for {@link HtmlPage}.
Expand Down Expand Up @@ -998,7 +1000,7 @@ public void asXml2() throws Exception {
assertNotNull("xml document could not be parsed", page.asXml());
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
builder.parse(TextUtils.toInputStream(page.asXml()));
builder.parse(IOUtils.toInputStream(page.asXml(), StandardCharsets.ISO_8859_1));
}

/**
Expand All @@ -1014,7 +1016,7 @@ public void asXml_unicode() throws Exception {
final WebClient client = getWebClient();
final MockWebConnection webConnection = new MockWebConnection();

webConnection.setDefaultResponse(TextUtils.stringToByteArray(html, UTF_8), 200, "OK", MimeType.TEXT_HTML);
webConnection.setDefaultResponse(StringUtils.toByteArray(html, UTF_8), 200, "OK", MimeType.TEXT_HTML);
client.setWebConnection(webConnection);

final HtmlPage page = client.getPage(URL_FIRST);
Expand Down
Loading