summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryyangi8r2013-10-16 04:19:33 (EDT)
committerGerrit Code Review @ Eclipse.org2013-10-16 09:05:52 (EDT)
commit9f8a737c043f8e87c74a7dce3c49f6a748fe481d (patch)
tree49825dcada075426be0f732513b827f61a16bba1
parente46036e954b6016c059b71ab94f13b6211d3d76f (diff)
downloadorg.eclipse.ptp-9f8a737c043f8e87c74a7dce3c49f6a748fe481d.zip
org.eclipse.ptp-9f8a737c043f8e87c74a7dce3c49f6a748fe481d.tar.gz
org.eclipse.ptp-9f8a737c043f8e87c74a7dce3c49f6a748fe481d.tar.bz2
Bug 417292 - Escape Character Added to Build Variable String Insiderefs/changes/51/16451/4
Quotes Change-Id: Ia3a55de2011a7af22de4db2fef0bc4f5bb337da1 Signed-off-by: yyangi8r <bjyangyy@cn.ibm.com>
-rw-r--r--core/org.eclipse.ptp.remote.rse.core/src/org/eclipse/ptp/remote/rse/core/RSEProcessBuilder.java50
1 files changed, 48 insertions, 2 deletions
diff --git a/core/org.eclipse.ptp.remote.rse.core/src/org/eclipse/ptp/remote/rse/core/RSEProcessBuilder.java b/core/org.eclipse.ptp.remote.rse.core/src/org/eclipse/ptp/remote/rse/core/RSEProcessBuilder.java
index 2eec99f..5e447a7 100644
--- a/core/org.eclipse.ptp.remote.rse.core/src/org/eclipse/ptp/remote/rse/core/RSEProcessBuilder.java
+++ b/core/org.eclipse.ptp.remote.rse.core/src/org/eclipse/ptp/remote/rse/core/RSEProcessBuilder.java
@@ -213,11 +213,57 @@ public class RSEProcessBuilder extends AbstractRemoteProcessBuilder {
return null;
}
- private String spaceEscapify(String inputString) {
+ /**
+ * Escape spaces. Only spaces inside a PAIR of single/double quotes would be taken as part of the string and remains.
+ * For strings with not balanced quotes, such as <abc'd ef>, will not result in the space being escaped.
+ *
+ * @param inputString
+ * @return
+ */
+ private static String spaceEscapify(String inputString) {
+ String result = null;
if (inputString == null) {
return null;
+ }else{
+ char[] array = inputString.toCharArray();
+ StringBuffer buffer = new StringBuffer();
+ boolean doubleQuote = false;
+ boolean singleQuote = false;
+ for (int i = 0; i < array.length; i++) {
+ char c = array[i];
+ if (c == '"') {
+ // Check if there is space inside single/double quotes.
+ if (i > 0 && array[i - 1] == '\\') {
+ doubleQuote = false;
+ } else if (doubleQuote){
+ // Met the second double quotes, spaces outside would be escaped
+ // So reset the doubleComment flag and singleComment flag to false;
+ doubleQuote = !doubleQuote;
+ singleQuote = false;
+ }else {
+ // Met the first double quotes, so change the flag to indicate inside the doubleComment
+ doubleQuote = !doubleQuote;
+ }
+ }else if (c == '\''){
+ if (i > 0 && array[i - 1] == '\\') {
+ singleQuote = false;
+ } else if (singleQuote){
+ singleQuote = !singleQuote;
+ doubleQuote = false;
+ }else {
+ singleQuote = !singleQuote;
+ }
+ }
+ if (c == ' ' && !doubleQuote && !singleQuote) {
+ buffer.append('\\');
+ buffer.append(c);
+ } else {
+ buffer.append(c);
+ }
+ }
+ result = buffer.toString();
}
- return inputString.replaceAll(" ", "\\\\ "); //$NON-NLS-1$ //$NON-NLS-2$
+ return result;
}
/*