public static bool IsCombinedUriWithin(Uri first, Uri second) { if (first == (Uri)null || second == (Uri)null) { return(false); } if (!second.IsAbsoluteUri) { Uri combinedUri = (Uri)null; if (!UriHelperUtility.TryCombineUris(first, second, out combinedUri)) { return(false); } second = combinedUri; } return(UriHelperUtility.IsUriWithin(second, first)); }
public static bool TryCombineUris(Uri rootUri, Uri relativeUri, out Uri combinedUri) { combinedUri = (Uri)null; if (rootUri == (Uri)null && relativeUri == (Uri)null) { return(false); } if (relativeUri == (Uri)null) { combinedUri = rootUri; return(true); } if (relativeUri.IsAbsoluteUri || UriHelperUtility.IsSdkUri(relativeUri)) { return(false); } if (rootUri == (Uri)null) { combinedUri = relativeUri; return(true); } if (UriHelperUtility.IsSdkUri(rootUri)) { return(UriHelperUtility.TryCombineSdkUris(rootUri, relativeUri, out combinedUri)); } rootUri = UriHelperUtility.EnsureUriEndsWithDirectorySeperator(rootUri); string originalString = relativeUri.OriginalString; if (Path.IsPathRooted(originalString)) { string pathRoot = Path.GetPathRoot(originalString); relativeUri = new Uri(originalString.Substring(pathRoot.Length), UriKind.Relative); } if (rootUri.IsAbsoluteUri) { return(Uri.TryCreate(rootUri, relativeUri, out combinedUri)); } string fromPath = "C:\\"; int length = rootUri.OriginalString.Split(new string[1] { ".." }, StringSplitOptions.None).Length; while (length-- > 0) { fromPath = fromPath + (object)"dummy" + (string)(object)Path.DirectorySeparatorChar; } rootUri = new Uri(fromPath + rootUri.ToString(), UriKind.Absolute); if (!UriHelperUtility.TryCombineUris(rootUri, relativeUri, out combinedUri)) { combinedUri = (Uri)null; return(false); } string relativePath = PathHelper.GetRelativePath(fromPath, combinedUri.LocalPath); if (string.IsNullOrEmpty(relativePath)) { combinedUri = (Uri)null; return(false); } combinedUri = new Uri(relativePath, UriKind.Relative); return(true); }