Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBJ Hargrave2013-03-01 16:24:11 +0000
committerBJ Hargrave2013-03-01 16:24:11 +0000
commit12c786df6185fabfdc282846f6c9fd14a0d185d3 (patch)
tree56e21526cff4d8bfa6c7145ed0cf42ee7ec26408 /bundles/org.eclipse.osgi/osgi/src/org
parentcd5b272d91228957cd584c6c399ca367b59073d9 (diff)
downloadrt.equinox.framework-12c786df6185fabfdc282846f6c9fd14a0d185d3.tar.gz
rt.equinox.framework-12c786df6185fabfdc282846f6c9fd14a0d185d3.tar.xz
rt.equinox.framework-12c786df6185fabfdc282846f6c9fd14a0d185d3.zip
OSGi bug 2502: Allows spaces around ';' and ',' in DNChain pattern
Signed-off-by: BJ Hargrave <hargrave@us.ibm.com>
Diffstat (limited to 'bundles/org.eclipse.osgi/osgi/src/org')
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java60
1 files changed, 32 insertions, 28 deletions
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java
index 5112a2301..e7209cd11 100644
--- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2005, 2012). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2005, 2013). All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1772,45 +1772,51 @@ public class FrameworkUtil {
* wildcard ("*"), or a List of Strings, each String representing a
* name/value pair in the RDN.
*
- * @param dnChain
+ * @param pattern
* @return a list of DNs.
* @throws IllegalArgumentException
*/
- private static List<Object> parseDNchainPattern(String dnChain) {
- if (dnChain == null) {
- throw new IllegalArgumentException("The DN chain must not be null.");
+ private static List<Object> parseDNchainPattern(String pattern) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("The pattern must not be null.");
}
List<Object> parsed = new ArrayList<Object>();
- int startIndex = 0;
- startIndex = skipSpaces(dnChain, startIndex);
- while (startIndex < dnChain.length()) {
+ final int length = pattern.length();
+ char c = ';'; // start with semi-colon to detect empty pattern
+ for (int startIndex = skipSpaces(pattern, 0); startIndex < length;) {
+ int cursor = startIndex;
int endIndex = startIndex;
- boolean inQuote = false;
- out: while (endIndex < dnChain.length()) {
- char c = dnChain.charAt(endIndex);
+ out: for (boolean inQuote = false; cursor < length; cursor++) {
+ c = pattern.charAt(cursor);
switch (c) {
case '"' :
inQuote = !inQuote;
break;
case '\\' :
- endIndex++; // skip the escaped char
+ cursor++; // skip the escaped char
+ if (cursor == length) {
+ throw new IllegalArgumentException("unterminated escape");
+ }
break;
case ';' :
- if (!inQuote)
- break out;
+ if (!inQuote) {
+ break out; // end of pattern
+ }
+ break;
+ }
+ if (c != ' ') { // ignore trailing whitespace
+ endIndex = cursor + 1;
}
- endIndex++;
- }
- if (endIndex > dnChain.length()) {
- throw new IllegalArgumentException("unterminated escape");
}
- parsed.add(dnChain.substring(startIndex, endIndex));
- startIndex = endIndex + 1;
- startIndex = skipSpaces(dnChain, startIndex);
+ parsed.add(pattern.substring(startIndex, endIndex));
+ startIndex = skipSpaces(pattern, cursor + 1);
+ }
+ if (c == ';') { // last non-whitespace character was a semi-colon
+ throw new IllegalArgumentException("empty pattern");
}
- // Now we parse is a list of strings, lets make List of rdn out
- // of them
+ // Now we have parsed into a list of strings, lets make List of rdn
+ // out of them
for (int i = 0; i < parsed.size(); i++) {
String dn = (String) parsed.get(i);
if (dn.equals(STAR_WILDCARD) || dn.equals(MINUS_WILDCARD)) {
@@ -1818,11 +1824,12 @@ public class FrameworkUtil {
}
List<Object> rdns = new ArrayList<Object>();
if (dn.charAt(0) == '*') {
- if (dn.charAt(1) != ',') {
+ int index = skipSpaces(dn, 1);
+ if (dn.charAt(index) != ',') {
throw new IllegalArgumentException("invalid wildcard prefix");
}
rdns.add(STAR_WILDCARD);
- dn = new X500Principal(dn.substring(2)).getName(X500Principal.CANONICAL);
+ dn = new X500Principal(dn.substring(index + 1)).getName(X500Principal.CANONICAL);
} else {
dn = new X500Principal(dn).getName(X500Principal.CANONICAL);
}
@@ -1830,9 +1837,6 @@ public class FrameworkUtil {
parseDN(dn, rdns);
parsed.set(i, rdns);
}
- if (parsed.size() == 0) {
- throw new IllegalArgumentException("empty DN chain");
- }
return parsed;
}

Back to the top