diff --git a/src/org/mozilla/javascript/commonjs/module/provider/UrlModuleSourceProvider.java b/src/org/mozilla/javascript/commonjs/module/provider/UrlModuleSourceProvider.java index 7decc72f72..7ada3f8bc9 100644 --- a/src/org/mozilla/javascript/commonjs/module/provider/UrlModuleSourceProvider.java +++ b/src/org/mozilla/javascript/commonjs/module/provider/UrlModuleSourceProvider.java @@ -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) { diff --git a/testsrc/org/mozilla/javascript/tests/commonjs/module/provider/UrlModuleSourceProviderTest.java b/testsrc/org/mozilla/javascript/tests/commonjs/module/provider/UrlModuleSourceProviderTest.java index 4924b1afd8..70b8e6c6b1 100644 --- a/testsrc/org/mozilla/javascript/tests/commonjs/module/provider/UrlModuleSourceProviderTest.java +++ b/testsrc/org/mozilla/javascript/tests/commonjs/module/provider/UrlModuleSourceProviderTest.java @@ -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; @@ -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('.')));