Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
 - Remove duplicate code
 - Use standard mechanism to pre-load classes for the SecurityManager

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1710313 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Oct 24, 2015
1 parent a890684 commit 0040f2a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 39 deletions.
21 changes: 1 addition & 20 deletions java/org/apache/catalina/connector/Response.java
Expand Up @@ -81,9 +81,6 @@ public class Response
private static final boolean ENFORCE_ENCODING_IN_GET_WRITER;

static {
// Ensure that URL is loaded for SM
URL.isSchemeChar('c');

ENFORCE_ENCODING_IN_GET_WRITER = Boolean.valueOf(
System.getProperty("org.apache.catalina.connector.Response.ENFORCE_ENCODING_IN_GET_WRITER",
"true")).booleanValue();
Expand Down Expand Up @@ -1593,7 +1590,7 @@ protected String toAbsolute(String location) {
throw iae;
}

} else if (leadingSlash || !hasScheme(location)) {
} else if (leadingSlash || !URL.hasScheme(location)) {

redirectURLCC.recycle();

Expand Down Expand Up @@ -1768,22 +1765,6 @@ private boolean hasPath(String uri) {
return true;
}

/**
* Determine if a URI string has a <code>scheme</code> component.
*/
private boolean hasScheme(String uri) {
int len = uri.length();
for(int i=0; i < len ; i++) {
char c = uri.charAt(i);
if(c == ':') {
return i > 0;
} else if(!URL.isSchemeChar(c)) {
return false;
}
}
return false;
}

/**
* Return the specified URL with the specified session identifier
* suitably encoded.
Expand Down
1 change: 1 addition & 0 deletions java/org/apache/catalina/security/SecurityClassLoad.java
Expand Up @@ -286,6 +286,7 @@ private static final void loadTomcatPackage(ClassLoader loader)
"util.net.NioBlockingSelector$BlockPoller$2");
loader.loadClass(basePackage +
"util.net.NioBlockingSelector$BlockPoller$3");
loader.loadClass(basePackage + "util.net.URL");
// security
loader.loadClass(basePackage + "util.security.PrivilegedGetTccl");
loader.loadClass(basePackage + "util.security.PrivilegedSetTccl");
Expand Down
19 changes: 1 addition & 18 deletions java/org/apache/catalina/valves/rewrite/RewriteValve.java
Expand Up @@ -344,7 +344,7 @@ else if (index == urlString.length() - 1) {
// 1. this valve is associated with a context
// 2. the url starts with a leading slash
// 3. the url isn't absolute
if (context && urlString.charAt(0) == '/' && !hasScheme(urlString)) {
if (context && urlString.charAt(0) == '/' && !URL.hasScheme(urlString)) {
urlString.insert(0, request.getContext().getEncodedPath());
}
response.sendRedirect(urlString.toString());
Expand Down Expand Up @@ -735,21 +735,4 @@ protected static void parseRuleFlag(String line, RewriteRule rule, String flag)
throw new IllegalArgumentException("Invalid flag in: " + line + " flag: " + flag);
}
}


/**
* Determine if a URI string has a <code>scheme</code> component.
*/
protected static boolean hasScheme(StringBuffer uri) {
int len = uri.length();
for(int i=0; i < len ; i++) {
char c = uri.charAt(i);
if(c == ':') {
return i > 0;
} else if(!URL.isSchemeChar(c)) {
return false;
}
}
return false;
}
}
26 changes: 25 additions & 1 deletion java/org/apache/tomcat/util/net/URL.java
Expand Up @@ -648,10 +648,34 @@ private void parse(String spec, int start, int limit)
/**
* Determine if the character is allowed in the scheme of a URI.
* See RFC 2396, Section 3.1
*
* @param c The character to test
*
* @return {@code true} if a the character is allowed, otherwise {@false}
*/
public static boolean isSchemeChar(char c) {
private static boolean isSchemeChar(char c) {
return Character.isLetterOrDigit(c) ||
c == '+' || c == '-' || c == '.';
}


/**
* Determine if a URI string has a <code>scheme</code> component.
*
* @param uri The URI to test
*
* @return {@code true} if a scheme is present, otherwise {@false}
*/
public static boolean hasScheme(CharSequence uri) {
int len = uri.length();
for(int i=0; i < len ; i++) {
char c = uri.charAt(i);
if(c == ':') {
return i > 0;
} else if(!URL.isSchemeChar(c)) {
return false;
}
}
return false;
}
}

0 comments on commit 0040f2a

Please sign in to comment.