StringUtil.csvSplit(String)
This commit is contained in:
parent
9d8d56b401
commit
3e401a62e9
|
@ -46,6 +46,7 @@ import org.eclipse.jetty.annotations.AnnotationParser.Handler;
|
|||
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
||||
import org.eclipse.jetty.util.ConcurrentHashSet;
|
||||
import org.eclipse.jetty.util.MultiException;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -272,7 +273,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
{
|
||||
_ordering = ordering;
|
||||
|
||||
String[] tmp = ordering.split(",");
|
||||
String[] tmp = StringUtil.csvSplit(ordering);
|
||||
|
||||
for (int i=0; i<tmp.length; i++)
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.jetty.client.api.ContentResponse;
|
|||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.util.Attributes;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
|
||||
/**
|
||||
|
@ -102,7 +103,7 @@ public class DigestAuthentication implements Authentication
|
|||
String clientQOP = null;
|
||||
if (serverQOP != null)
|
||||
{
|
||||
List<String> serverQOPValues = Arrays.asList(serverQOP.split(","));
|
||||
List<String> serverQOPValues = StringUtil.csvSplit(null,serverQOP,0,serverQOP.length());
|
||||
if (serverQOPValues.contains("auth"))
|
||||
clientQOP = "auth";
|
||||
else if (serverQOPValues.contains("auth-int"))
|
||||
|
|
|
@ -638,7 +638,7 @@ public class HttpGenerator
|
|||
|
||||
if (values[0]==null)
|
||||
{
|
||||
split = field.getValue().split("\\s*,\\s*");
|
||||
split = StringUtil.csvSplit(field.getValue());
|
||||
if (split.length>0)
|
||||
{
|
||||
values=new HttpHeaderValue[split.length];
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.eclipse.jetty.server.handler.ContextHandler;
|
|||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.util.PathWatcher;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
|
@ -703,7 +704,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
|||
}
|
||||
else
|
||||
{
|
||||
String[] files = this.jettyXml.split(",");
|
||||
String[] files = StringUtil.csvSplit(this.jettyXml);
|
||||
|
||||
for ( String file : files )
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.jetty.servlet.FilterHolder;
|
|||
import org.eclipse.jetty.servlet.FilterMapping;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.servlet.ServletMapping;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -253,7 +254,7 @@ public class JettyWebAppContext extends WebAppContext
|
|||
List<String> resources = new ArrayList<String>();
|
||||
for (String rl:resourceBases)
|
||||
{
|
||||
String[] rs = rl.split(" *, *");
|
||||
String[] rs = StringUtil.csvSplit(rl);
|
||||
for (String r:rs)
|
||||
resources.add(r);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
/**
|
||||
* OverlayConfig
|
||||
|
@ -46,7 +47,7 @@ public class OverlayConfig
|
|||
{
|
||||
if (fmt == null)
|
||||
return;
|
||||
String[] atoms = fmt.split(",");
|
||||
String[] atoms = StringUtil.csvSplit(fmt);
|
||||
for (int i=0;i<atoms.length;i++)
|
||||
{
|
||||
String s = atoms[i].trim();
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.jetty.server.Handler;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ShutdownMonitor;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -81,7 +82,7 @@ public class Starter
|
|||
{
|
||||
if (csv != null && !"".equals(csv))
|
||||
{
|
||||
String[] atoms = csv.split(",");
|
||||
String[] atoms = StringUtil.csvSplit(csv);
|
||||
if (atoms.length >= 3)
|
||||
{
|
||||
gid = atoms[0].trim();
|
||||
|
@ -197,7 +198,7 @@ public class Starter
|
|||
str = (String)props.getProperty("base.dirs");
|
||||
if (str != null && !"".equals(str.trim()))
|
||||
{
|
||||
ResourceCollection bases = new ResourceCollection(str.split(","));
|
||||
ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str));
|
||||
webApp.setWar(null);
|
||||
webApp.setBaseResource(bases);
|
||||
}
|
||||
|
@ -206,7 +207,7 @@ public class Starter
|
|||
str = (String)props.get("base.dirs.orig");
|
||||
if (str != null && !"".equals(str.trim()))
|
||||
{
|
||||
ResourceCollection bases = new ResourceCollection(str.split(","));
|
||||
ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str));
|
||||
webApp.setAttribute ("org.eclipse.jetty.resources.originalBases", bases);
|
||||
}
|
||||
|
||||
|
@ -302,7 +303,7 @@ public class Starter
|
|||
if (str != null && !"".equals(str.trim()))
|
||||
{
|
||||
List<File> jars = new ArrayList<File>();
|
||||
String[] names = str.split(",");
|
||||
String[] names = StringUtil.csvSplit(str);
|
||||
for (int j=0; names != null && j < names.length; j++)
|
||||
jars.add(new File(names[j].trim()));
|
||||
webApp.setWebInfLib(jars);
|
||||
|
@ -327,7 +328,7 @@ public class Starter
|
|||
if ("--jetty-xml".equals(args[i]))
|
||||
{
|
||||
jettyXmls = new ArrayList<File>();
|
||||
String[] names = args[++i].split(",");
|
||||
String[] names = StringUtil.csvSplit(args[++i]);
|
||||
for (int j=0; names!= null && j < names.length; j++)
|
||||
{
|
||||
jettyXmls.add(new File(names[j].trim()));
|
||||
|
@ -441,7 +442,7 @@ public class Starter
|
|||
{
|
||||
if (csv == null || "".equals(csv.trim()))
|
||||
return null;
|
||||
String[] atoms = csv.split(",");
|
||||
String[] atoms = StringUtil.csvSplit(csv);
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (String a:atoms)
|
||||
{
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
/**
|
||||
* WarPluginInfo
|
||||
|
@ -99,7 +100,7 @@ public class WarPluginInfo
|
|||
if (node == null)
|
||||
return null;
|
||||
String val = node.getValue();
|
||||
_dependentMavenWarIncludes = Arrays.asList(val.split(","));
|
||||
_dependentMavenWarIncludes = StringUtil.csvSplit(null,val,0,val.length());
|
||||
}
|
||||
return _dependentMavenWarIncludes;
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ public class WarPluginInfo
|
|||
if (node == null)
|
||||
return null;
|
||||
String val = node.getValue();
|
||||
_dependentMavenWarExcludes = Arrays.asList(val.split(","));
|
||||
_dependentMavenWarExcludes = StringUtil.csvSplit(null,val,0,val.length());
|
||||
}
|
||||
return _dependentMavenWarExcludes;
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public class Main
|
|||
String argValue = matcher.group(2);
|
||||
if (argValue.startsWith("host,"))
|
||||
{
|
||||
String[] typeAndSuffix = argValue.split(",");
|
||||
String[] typeAndSuffix = StringUtil.split(argValue);
|
||||
if (typeAndSuffix.length != 2)
|
||||
throw new IllegalArgumentException("Invalid option " + arg + ", must be of the form --" + RETRIEVER_ARG + "=host,suffix");
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.eclipse.jetty.security.MappedLoginService.RolePrincipal;
|
|||
import org.eclipse.jetty.server.UserIdentity;
|
||||
import org.eclipse.jetty.util.PathWatcher;
|
||||
import org.eclipse.jetty.util.PathWatcher.PathWatchEvent;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -253,7 +254,7 @@ public class PropertyUserStore extends AbstractLifeCycle implements PathWatcher.
|
|||
String[] roleArray = IdentityService.NO_ROLES;
|
||||
if (roles != null && roles.length() > 0)
|
||||
{
|
||||
roleArray = roles.split(",");
|
||||
roleArray = StringUtil.csvSplit(roles);
|
||||
}
|
||||
known.add(username);
|
||||
Credential credential = Credential.getCredential(credentials);
|
||||
|
|
|
@ -1168,10 +1168,9 @@ public class Response implements HttpServletResponse
|
|||
|
||||
if (connection != null)
|
||||
{
|
||||
String[] values = connection.split(",");
|
||||
for (int i = 0; values != null && i < values.length; i++)
|
||||
for (String value: StringUtil.csvSplit(null,connection,0,connection.length()))
|
||||
{
|
||||
HttpHeaderValue cb = HttpHeaderValue.CACHE.get(values[0].trim());
|
||||
HttpHeaderValue cb = HttpHeaderValue.CACHE.get(value);
|
||||
|
||||
if (cb != null)
|
||||
{
|
||||
|
|
|
@ -759,7 +759,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
{
|
||||
String managedAttributes = _initParams.get(MANAGED_ATTRIBUTES);
|
||||
if (managedAttributes != null)
|
||||
addEventListener(new ManagedAttributeListener(this,managedAttributes.split(",")));
|
||||
addEventListener(new ManagedAttributeListener(this,StringUtil.csvSplit(managedAttributes)));
|
||||
|
||||
super.doStart();
|
||||
|
||||
|
@ -970,8 +970,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
{
|
||||
// check the target.
|
||||
if (DispatcherType.REQUEST.equals(dispatch) ||
|
||||
DispatcherType.ASYNC.equals(dispatch) ||
|
||||
DispatcherType.ERROR.equals(dispatch) && baseRequest.getHttpChannelState().isAsync())
|
||||
DispatcherType.ASYNC.equals(dispatch) ||
|
||||
DispatcherType.ERROR.equals(dispatch) && baseRequest.getHttpChannelState().isAsync())
|
||||
{
|
||||
if (_compactPath)
|
||||
target = URIUtil.compactPath(target);
|
||||
|
|
|
@ -36,6 +36,7 @@ import javax.servlet.ServletResponse;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
@ -155,7 +156,7 @@ public class CrossOriginFilter implements Filter
|
|||
String allowedOriginsConfig = config.getInitParameter(ALLOWED_ORIGINS_PARAM);
|
||||
if (allowedOriginsConfig == null)
|
||||
allowedOriginsConfig = "*";
|
||||
String[] allowedOrigins = allowedOriginsConfig.split(",");
|
||||
String[] allowedOrigins = StringUtil.csvSplit(allowedOriginsConfig);
|
||||
for (String allowedOrigin : allowedOrigins)
|
||||
{
|
||||
allowedOrigin = allowedOrigin.trim();
|
||||
|
@ -178,7 +179,7 @@ public class CrossOriginFilter implements Filter
|
|||
if (allowedMethodsConfig == null)
|
||||
allowedMethods.addAll(DEFAULT_ALLOWED_METHODS);
|
||||
else
|
||||
allowedMethods.addAll(Arrays.asList(allowedMethodsConfig.split(",")));
|
||||
allowedMethods.addAll(Arrays.asList(StringUtil.csvSplit(allowedMethodsConfig)));
|
||||
|
||||
String allowedHeadersConfig = config.getInitParameter(ALLOWED_HEADERS_PARAM);
|
||||
if (allowedHeadersConfig == null)
|
||||
|
@ -186,7 +187,7 @@ public class CrossOriginFilter implements Filter
|
|||
else if ("*".equals(allowedHeadersConfig))
|
||||
anyHeadersAllowed = true;
|
||||
else
|
||||
allowedHeaders.addAll(Arrays.asList(allowedHeadersConfig.split(",")));
|
||||
allowedHeaders.addAll(Arrays.asList(StringUtil.csvSplit(allowedHeadersConfig)));
|
||||
|
||||
String preflightMaxAgeConfig = config.getInitParameter(PREFLIGHT_MAX_AGE_PARAM);
|
||||
if (preflightMaxAgeConfig == null)
|
||||
|
@ -208,7 +209,7 @@ public class CrossOriginFilter implements Filter
|
|||
String exposedHeadersConfig = config.getInitParameter(EXPOSED_HEADERS_PARAM);
|
||||
if (exposedHeadersConfig == null)
|
||||
exposedHeadersConfig = "";
|
||||
exposedHeaders.addAll(Arrays.asList(exposedHeadersConfig.split(",")));
|
||||
exposedHeaders.addAll(Arrays.asList(StringUtil.csvSplit(exposedHeadersConfig)));
|
||||
|
||||
String chainPreflightConfig = config.getInitParameter(OLD_CHAIN_PREFLIGHT_PARAM);
|
||||
if (chainPreflightConfig != null)
|
||||
|
@ -419,7 +420,7 @@ public class CrossOriginFilter implements Filter
|
|||
return Collections.emptyList();
|
||||
|
||||
List<String> requestedHeaders = new ArrayList<String>();
|
||||
String[] headers = accessControlRequestHeaders.split(",");
|
||||
String[] headers = StringUtil.csvSplit(accessControlRequestHeaders);
|
||||
for (String header : headers)
|
||||
{
|
||||
String h = header.trim();
|
||||
|
|
|
@ -52,6 +52,7 @@ import javax.servlet.http.HttpSessionBindingListener;
|
|||
import javax.servlet.http.HttpSessionEvent;
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
|
@ -1043,7 +1044,7 @@ public class DoSFilter implements Filter
|
|||
public void setWhitelist(String commaSeparatedList)
|
||||
{
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String address : commaSeparatedList.split(","))
|
||||
for (String address : StringUtil.csvSplit(commaSeparatedList))
|
||||
addWhitelistAddress(result, address);
|
||||
clearWhitelist();
|
||||
_whitelist.addAll(result);
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.eclipse.jetty.http.HttpHeader;
|
|||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.server.Dispatcher;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
|
@ -95,11 +96,11 @@ public class PushCacheFilter implements Filter
|
|||
|
||||
String hosts = config.getInitParameter("hosts");
|
||||
if (hosts != null)
|
||||
Collections.addAll(_hosts, hosts.split(","));
|
||||
Collections.addAll(_hosts, StringUtil.csvSplit(hosts));
|
||||
|
||||
String ports = config.getInitParameter("ports");
|
||||
if (ports != null)
|
||||
for (String p : ports.split(","))
|
||||
for (String p : StringUtil.csvSplit(ports))
|
||||
_ports.add(Integer.parseInt(p));
|
||||
|
||||
// Expose for JMX.
|
||||
|
|
|
@ -44,6 +44,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.servlet.http.HttpServletResponseWrapper;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
|
||||
/**
|
||||
|
@ -331,7 +332,7 @@ public class PutFilter implements Filter
|
|||
if ("Allow".equalsIgnoreCase(name))
|
||||
{
|
||||
Set<String> options = new HashSet<String>();
|
||||
options.addAll(Arrays.asList(value.split(" *, *")));
|
||||
options.addAll(Arrays.asList(StringUtil.csvSplit(value)));
|
||||
options.addAll(_operations);
|
||||
value=null;
|
||||
for (String o : options)
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.jetty.servlet.FilterHolder;
|
|||
import org.eclipse.jetty.servlet.ServletTester;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -266,8 +267,8 @@ public class PutFilterTest
|
|||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
|
||||
Set<String> options = new HashSet<String>();
|
||||
options.addAll(Arrays.asList(response.get("Allow").split(" *, *")));
|
||||
|
||||
String allow=response.get("Allow");
|
||||
options.addAll(StringUtil.csvSplit(null,allow,0,allow.length()));
|
||||
assertTrue(options.contains("GET"));
|
||||
assertTrue(options.contains("POST"));
|
||||
assertTrue(options.contains("PUT"));
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.eclipse.jetty.util;
|
|||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -733,6 +735,11 @@ public class StringUtil
|
|||
return str.substring(0,maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the string representation of a list using {@link #csvSplit(List,String,int,int)}
|
||||
* @param s The string to parse, expected to be enclosed as '[...]'
|
||||
* @return An array of parsed values.
|
||||
*/
|
||||
public static String[] arrayFromString(String s)
|
||||
{
|
||||
if (s==null)
|
||||
|
@ -743,9 +750,183 @@ public class StringUtil
|
|||
if (s.length()==2)
|
||||
return new String[]{};
|
||||
|
||||
return s.substring(1,s.length()-1).split("\\s*,\\s*");
|
||||
return csvSplit(s,1,s.length()-2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a CSV string using {@link #csvSplit(List,String, int, int)}
|
||||
* @param s The string to parse
|
||||
* @return An array of parsed values.
|
||||
*/
|
||||
public static String[] csvSplit(String s)
|
||||
{
|
||||
if (s==null)
|
||||
return null;
|
||||
return csvSplit(s,0,s.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a CSV string using {@link #csvSplit(List,String, int, int)}
|
||||
* @param s The string to parse
|
||||
* @param off The offset into the string to start parsing
|
||||
* @param len The len in characters to parse
|
||||
* @return An array of parsed values.
|
||||
*/
|
||||
public static String[] csvSplit(String s, int off,int len)
|
||||
{
|
||||
if (s==null)
|
||||
return null;
|
||||
if (off<0 || len<0 || off>s.length())
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
csvSplit(list,s,off,len);
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
enum CsvSplitState { PRE_DATA, QUOTE, SLOSH, DATA, WHITE, POST_DATA };
|
||||
|
||||
/** Split a quoted comma separated string to a list
|
||||
* <p>Handle <a href="https://www.ietf.org/rfc/rfc4180.txt">rfc4180</a>-like
|
||||
* CSV strings, with the exceptions:<ul>
|
||||
* <li>quoted values may contain double quotes escaped with back-slash
|
||||
* <li>Non-quoted values are trimmed of leading trailing white space
|
||||
* <li>trailing commas are ignored
|
||||
* <li>double commas result in a empty string value
|
||||
* </ul>
|
||||
* @param list The Collection to split to (or null to get a new list)
|
||||
* @param s The string to parse
|
||||
* @param off The offset into the string to start parsing
|
||||
* @param len The len in characters to parse
|
||||
* @return list containing the parsed list values
|
||||
*/
|
||||
public static List<String> csvSplit(List<String> list,String s, int off,int len)
|
||||
{
|
||||
if (list==null)
|
||||
list=new ArrayList<>();
|
||||
CsvSplitState state = CsvSplitState.PRE_DATA;
|
||||
StringBuilder out = new StringBuilder();
|
||||
int last=-1;
|
||||
while (len>0)
|
||||
{
|
||||
char ch = s.charAt(off++);
|
||||
len--;
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case PRE_DATA:
|
||||
if (Character.isWhitespace(ch))
|
||||
continue;
|
||||
|
||||
if ('"'==ch)
|
||||
{
|
||||
state=CsvSplitState.QUOTE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (','==ch)
|
||||
{
|
||||
list.add("");
|
||||
continue;
|
||||
}
|
||||
|
||||
state=CsvSplitState.DATA;
|
||||
out.append(ch);
|
||||
continue;
|
||||
|
||||
case DATA:
|
||||
if (Character.isWhitespace(ch))
|
||||
{
|
||||
last=out.length();
|
||||
out.append(ch);
|
||||
state=CsvSplitState.WHITE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (','==ch)
|
||||
{
|
||||
list.add(out.toString());
|
||||
out.setLength(0);
|
||||
state=CsvSplitState.PRE_DATA;
|
||||
continue;
|
||||
}
|
||||
|
||||
out.append(ch);
|
||||
continue;
|
||||
|
||||
case WHITE:
|
||||
if (Character.isWhitespace(ch))
|
||||
{
|
||||
out.append(ch);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (','==ch)
|
||||
{
|
||||
out.setLength(last);
|
||||
list.add(out.toString());
|
||||
out.setLength(0);
|
||||
state=CsvSplitState.PRE_DATA;
|
||||
continue;
|
||||
}
|
||||
|
||||
state=CsvSplitState.DATA;
|
||||
out.append(ch);
|
||||
last=-1;
|
||||
continue;
|
||||
|
||||
case QUOTE:
|
||||
if ('\\'==ch)
|
||||
{
|
||||
state=CsvSplitState.SLOSH;
|
||||
continue;
|
||||
}
|
||||
if ('"'==ch)
|
||||
{
|
||||
list.add(out.toString());
|
||||
out.setLength(0);
|
||||
state=CsvSplitState.POST_DATA;
|
||||
continue;
|
||||
}
|
||||
out.append(ch);
|
||||
continue;
|
||||
|
||||
case SLOSH:
|
||||
out.append(ch);
|
||||
state=CsvSplitState.QUOTE;
|
||||
continue;
|
||||
|
||||
case POST_DATA:
|
||||
if (','==ch)
|
||||
{
|
||||
state=CsvSplitState.PRE_DATA;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case PRE_DATA:
|
||||
case POST_DATA:
|
||||
break;
|
||||
|
||||
case DATA:
|
||||
case QUOTE:
|
||||
case SLOSH:
|
||||
list.add(out.toString());
|
||||
break;
|
||||
|
||||
case WHITE:
|
||||
out.setLength(last);
|
||||
list.add(out.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String sanitizeXmlString(String html)
|
||||
{
|
||||
if (html==null)
|
||||
|
@ -813,7 +994,6 @@ public class StringUtil
|
|||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** The String value of an Object
|
||||
|
|
|
@ -18,12 +18,17 @@
|
|||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayContaining;
|
||||
import static org.hamcrest.Matchers.emptyArray;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -241,4 +246,32 @@ public class StringUtilTest
|
|||
assertEquals("Hello <Cruel> World",StringUtil.sanitizeXmlString("Hello <Cruel> World"));
|
||||
assertEquals("Hello ? World",StringUtil.sanitizeXmlString("Hello \u0000 World"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplit()
|
||||
{
|
||||
assertThat(StringUtil.csvSplit(null),nullValue());
|
||||
assertThat(StringUtil.csvSplit(null),nullValue());
|
||||
|
||||
assertThat(StringUtil.csvSplit(""),emptyArray());
|
||||
assertThat(StringUtil.csvSplit(" \t\n"),emptyArray());
|
||||
|
||||
assertThat(StringUtil.csvSplit("aaa"),arrayContaining("aaa"));
|
||||
assertThat(StringUtil.csvSplit(" \taaa\n"),arrayContaining("aaa"));
|
||||
assertThat(StringUtil.csvSplit(" \ta\n"),arrayContaining("a"));
|
||||
assertThat(StringUtil.csvSplit(" \t\u1234\n"),arrayContaining("\u1234"));
|
||||
|
||||
assertThat(StringUtil.csvSplit("aaa,bbb,ccc"),arrayContaining("aaa","bbb","ccc"));
|
||||
assertThat(StringUtil.csvSplit("aaa,,ccc"),arrayContaining("aaa","","ccc"));
|
||||
assertThat(StringUtil.csvSplit(",b b,"),arrayContaining("","b b"));
|
||||
assertThat(StringUtil.csvSplit(",,bbb,,"),arrayContaining("","","bbb",""));
|
||||
|
||||
assertThat(StringUtil.csvSplit(" aaa, bbb, ccc"),arrayContaining("aaa","bbb","ccc"));
|
||||
assertThat(StringUtil.csvSplit("aaa,\t,ccc"),arrayContaining("aaa","","ccc"));
|
||||
assertThat(StringUtil.csvSplit(" , b b , "),arrayContaining("","b b"));
|
||||
assertThat(StringUtil.csvSplit(" ,\n,bbb, , "),arrayContaining("","","bbb",""));
|
||||
|
||||
assertThat(StringUtil.csvSplit("\"aaa\", \" b,\\\"\",\"\""),arrayContaining("aaa"," b,\"",""));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public class JsrBrowserSocket
|
|||
}
|
||||
case "many":
|
||||
{
|
||||
String parts[] = val.split(",");
|
||||
String parts[] = StringUtil.csvSplit(val);
|
||||
int size = Integer.parseInt(parts[0]);
|
||||
int count = Integer.parseInt(parts[1]);
|
||||
|
||||
|
@ -142,7 +142,7 @@ public class JsrBrowserSocket
|
|||
}
|
||||
case "manythreads":
|
||||
{
|
||||
String parts[] = val.split(",");
|
||||
String parts[] = StringUtil.csvSplit(val);
|
||||
int threadCount = Integer.parseInt(parts[0]);
|
||||
int size = Integer.parseInt(parts[1]);
|
||||
int count = Integer.parseInt(parts[2]);
|
||||
|
|
|
@ -1348,10 +1348,8 @@ public class XmlConfiguration
|
|||
|
||||
String attr = _node.getAttribute(attrName);
|
||||
if (attr!=null)
|
||||
{
|
||||
for (String a : attr.split(","))
|
||||
values.add(a);
|
||||
}
|
||||
values.addAll(StringUtil.csvSplit(null,attr,0,attr.length()));
|
||||
|
||||
|
||||
for (int i=0;i<_next;i++)
|
||||
{
|
||||
|
@ -1383,7 +1381,7 @@ public class XmlConfiguration
|
|||
String attr = _node.getAttribute(attrName);
|
||||
if (attr!=null)
|
||||
{
|
||||
for (String a : attr.split(","))
|
||||
for (String a : StringUtil.csvSplit(null,attr,0,attr.length()))
|
||||
{
|
||||
// create a fake node
|
||||
XmlParser.Node n = new XmlParser.Node(null,elementName,null);
|
||||
|
|
Loading…
Reference in New Issue