Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getCharacterEncoding in UrlModuleSourceProvider protected #1233

Merged
merged 3 commits into from
Jul 30, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ protected ModuleSource loadFromActualUri(URI uri, URI base, Object validator)
}
}

private static Reader getReader(URLConnection urlConnection) throws IOException {
private Reader getReader(URLConnection urlConnection) throws IOException {
return new InputStreamReader(
urlConnection.getInputStream(), getCharacterEncoding(urlConnection));
}

private static String getCharacterEncoding(URLConnection urlConnection) {
protected String getCharacterEncoding(URLConnection urlConnection) {
final ParsedContentType pct = new ParsedContentType(urlConnection.getContentType());
final String encoding = pct.getEncoding();
if (encoding != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package org.mozilla.javascript.tests.commonjs.module.provider;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
Expand Down Expand Up @@ -67,6 +70,15 @@ public void testModuleModified() throws Exception {
Assert.assertNotEquals("Modified", ModuleSourceProvider.NOT_MODIFIED, result);
}

@Test
public void getCharacterEncodingCanBeModifiedInSubclass() throws NoSuchMethodException {
Method method =
UrlModuleSourceProvider.class.getDeclaredMethod(
"getCharacterEncoding", new Class[] {URLConnection.class});
int mods = method.getModifiers();
Assert.assertTrue(Modifier.isPublic(mods) || Modifier.isProtected(mods));
}

private static URI getModuleURI(final Path filePath) throws URISyntaxException {
final String uriString = filePath.toUri().toASCIIString();
return new URI(uriString.substring(0, uriString.lastIndexOf('.')));
Expand Down