Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry BLIND2019-02-25 05:35:30 -0500
committerThierry BLIND2019-02-25 05:35:30 -0500
commitcc295ad99806429c42ce38752c24d4130462b65c (patch)
tree4f976ad129ce676251763e5e481ee70f2309dcad
parent20fa074da9b5d921e505da1d841ef27e6ebaea65 (diff)
downloadorg.eclipse.pdt-cc295ad99806429c42ce38752c24d4130462b65c.tar.gz
org.eclipse.pdt-cc295ad99806429c42ce38752c24d4130462b65c.tar.xz
org.eclipse.pdt-cc295ad99806429c42ce38752c24d4130462b65c.zip
No bug - fix UNC path handling in VirtualPath and PathMapperEntryDialog
Change-Id: I83f2278f4a2e02f05328a1ae0a44c97958694903 Signed-off-by: Thierry BLIND <thierryblind@msn.com>
-rw-r--r--plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/pathmapper/VirtualPath.java27
-rw-r--r--plugins/org.eclipse.php.debug.ui/src/org/eclipse/php/internal/debug/ui/pathmapper/PathMapperEntryDialog.java45
2 files changed, 55 insertions, 17 deletions
diff --git a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/pathmapper/VirtualPath.java b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/pathmapper/VirtualPath.java
index 3a810c56a..82df915fe 100644
--- a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/pathmapper/VirtualPath.java
+++ b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/pathmapper/VirtualPath.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
+ * Copyright (c) 2009, 2019 IBM Corporation and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -43,15 +43,18 @@ public class VirtualPath implements Cloneable {
if (path == null) {
throw new NullPointerException();
}
+ String originalPath = path;
if (path.startsWith("\\\\")) { // Network path //$NON-NLS-1$
sepChar = '\\';
device = "\\\\"; //$NON-NLS-1$
path = path.substring(2);
- }
- if (path.startsWith("\\")) { //$NON-NLS-1$
+ // Basic UNC checks:
+ if (path.length() == 0 || path.startsWith("\\") || path.startsWith("/")) {//$NON-NLS-1$ //$NON-NLS-2$
+ throw new IllegalArgumentException("Illegal or not full path: " + originalPath);//$NON-NLS-1$
+ }
+ } else if (path.startsWith("\\")) { //$NON-NLS-1$
sepChar = '\\';
device = "\\"; //$NON-NLS-1$
- path = path.substring(1);
} else {
Matcher m = VOLNAME.matcher(path);
if (m.matches()) { // Windows path
@@ -69,7 +72,7 @@ public class VirtualPath implements Cloneable {
device = m.group(1);
path = m.group(2);
} else {
- throw new IllegalArgumentException("Illegal or not full path: " + path);//$NON-NLS-1$
+ throw new IllegalArgumentException("Illegal or not full path: " + originalPath);//$NON-NLS-1$
}
}
}
@@ -85,6 +88,20 @@ public class VirtualPath implements Cloneable {
}
/**
+ * Checks whether the given path is a local file-system path, totally
+ * excluding UNC paths and URLs. For example paths starting with
+ * \\localhost\ or file:/// will not be seen as local paths.
+ *
+ * @param path
+ * @return <code>true</code> if given path is a local path, otherwise
+ * <code>false</code>
+ */
+ public static boolean isLocal(String path) {
+ return (VOLNAME.matcher(path).matches() || path.startsWith("/") //$NON-NLS-1$
+ || (path.startsWith("\\") && !path.startsWith("\\\\"))); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
* Checks whether the given path is absolute
*
* @param path
diff --git a/plugins/org.eclipse.php.debug.ui/src/org/eclipse/php/internal/debug/ui/pathmapper/PathMapperEntryDialog.java b/plugins/org.eclipse.php.debug.ui/src/org/eclipse/php/internal/debug/ui/pathmapper/PathMapperEntryDialog.java
index f6d067b48..bc311ddb4 100644
--- a/plugins/org.eclipse.php.debug.ui/src/org/eclipse/php/internal/debug/ui/pathmapper/PathMapperEntryDialog.java
+++ b/plugins/org.eclipse.php.debug.ui/src/org/eclipse/php/internal/debug/ui/pathmapper/PathMapperEntryDialog.java
@@ -346,6 +346,11 @@ public class PathMapperEntryDialog extends TitleAreaDialog {
setError(Messages.PathMapperEntryDialog_9);
return;
}
+ // XXX: Should we add following test?
+ // if (!VirtualPath.isLocal(remotePathStr)) {
+ // setError(Messages.PathMapperEntryDialog_10);
+ // return;
+ // }
try {
mapping.remotePath = new VirtualPath(remotePathStr);
} catch (IllegalArgumentException e) {
@@ -361,43 +366,59 @@ public class PathMapperEntryDialog extends TitleAreaDialog {
return;
}
+ // Workaround bug 542652 - Path Mapping for PHP Server does not
+ // accept UNC paths
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=542652
+ if (!VirtualPath.isLocal(workspacePath)) {
+ setError(Messages.PathMapperEntryDialog_13);
+ return;
+ }
+ try {
+ mapping.localPath = new VirtualPath(workspacePath);
+ } catch (IllegalArgumentException e) {
+ setError(Messages.PathMapperEntryDialog_13);
+ return;
+ }
boolean pathExistsInWorkspace = false;
mapping.type = (Type) fWorkspacePathText.getData();
if (mapping.type == Type.INCLUDE_FOLDER || mapping.type == Type.INCLUDE_VAR) {
- pathExistsInWorkspace = new File(workspacePath).exists();
+ pathExistsInWorkspace = new File(mapping.localPath.toString()).exists();
} else {
- pathExistsInWorkspace = (ResourcesPlugin.getWorkspace().getRoot().findMember(workspacePath) != null);
+ pathExistsInWorkspace = (ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(mapping.localPath.toString()) != null);
}
if (!pathExistsInWorkspace) {
setError(NLS.bind(Messages.PathMapperEntryDialog_12, workspacePath));
return;
}
- try {
- mapping.localPath = new VirtualPath(workspacePath);
- } catch (IllegalArgumentException e) {
- setError(Messages.PathMapperEntryDialog_13);
- return;
- }
} else if (ignoreMappingBtn.getSelection()) {
- mapping.type = Type.SERVER;
mapping.localPath = mapping.remotePath.clone();
+ mapping.type = Type.SERVER;
} else { // External file:
String externalPath = fExternalPathText.getText().trim();
if (externalPath.length() == 0) {
setError(Messages.PathMapperEntryDialog_14);
return;
}
- if (!new File(externalPath).exists()) {
- setError(NLS.bind(Messages.PathMapperEntryDialog_15, externalPath));
+
+ // Workaround bug 542652 - Path Mapping for PHP Server does not
+ // accept UNC paths
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=542652
+ if (!VirtualPath.isLocal(externalPath)) {
+ setError(Messages.PathMapperEntryDialog_16);
return;
}
try {
- mapping.type = Type.EXTERNAL;
mapping.localPath = new VirtualPath(externalPath);
} catch (IllegalArgumentException e) {
setError(Messages.PathMapperEntryDialog_16);
return;
}
+ mapping.type = Type.EXTERNAL;
+ if (!new File(mapping.localPath.toString()).exists()) {
+ setError(NLS.bind(Messages.PathMapperEntryDialog_15, externalPath));
+ return;
+ }
}
fEditData = mapping;

Back to the top