internal string Resolve_ClientUrl(string relativeUrl) { string sourceDirectory = this.TemplateSourceDirectory; if (sourceDirectory.Length == 0) { return(relativeUrl); } string baseDir = BaseDir; if (!UrlPath.IsAppRelativePath(relativeUrl)) { if (string.Compare(baseDir, sourceDirectory, true) == 0) { return(relativeUrl); } if ((relativeUrl.Length == 0) || !UrlPath.IsRelativeUrl(relativeUrl)) { return(relativeUrl); } } string text3 = UrlPath.Combine(sourceDirectory, relativeUrl); baseDir = UrlPath.AppendSlashToPathIfNeeded(baseDir); return(UrlPath.MakeRelative(baseDir, text3)); }
protected override void DeserializeSection(XmlReader reader) { WebContext context; base.DeserializeSection(reader); // Determine Web Context context = EvaluationContext.HostingContext as WebContext; if (context != null) { basepath = UrlPath.AppendSlashToPathIfNeeded(context.Path); } }
public static VirtualPath Create(string virtualPath, VirtualPathOptions options) { // Trim it first, so that blank strings (e.g. " ") get treated as empty if (virtualPath != null) { virtualPath = virtualPath.Trim(); } // If it's empty, check whether we allow it if (String.IsNullOrEmpty(virtualPath)) { if ((options & VirtualPathOptions.AllowNull) != 0) { return(null); } throw new ArgumentNullException("virtualPath"); } // Dev10 767308: optimize for normal paths, and scan once for // i) invalid chars // ii) slashes // iii) '.' bool slashes = false; bool dot = false; int len = virtualPath.Length; unsafe { fixed(char *p = virtualPath) { for (int i = 0; i < len; i++) { switch (p[i]) { // need to fix slashes ? case '/': if (i > 0 && p[i - 1] == '/') { slashes = true; } break; case '\\': slashes = true; break; // contains "." or ".." case '.': dot = true; break; // invalid chars case '\0': throw new Exception($"Invalid path {virtualPath}"); default: break; } } } } if (slashes) { // If we're supposed to fail on malformed path, then throw if ((options & VirtualPathOptions.FailIfMalformed) != 0) { throw new Exception($"Invalid path {virtualPath}"); } // Flip ----lashes, and remove duplicate slashes virtualPath = UrlPath.FixVirtualPathSlashes(virtualPath); } // Make sure it ends with a trailing slash if requested if ((options & VirtualPathOptions.EnsureTrailingSlash) != 0) { virtualPath = UrlPath.AppendSlashToPathIfNeeded(virtualPath); } VirtualPath virtualPathObject = new VirtualPath(); if (UrlPath.IsAppRelativePath(virtualPath)) { if (dot) { virtualPath = UrlPath.ReduceVirtualPath(virtualPath); } if (virtualPath[0] == UrlPath.appRelativeCharacter) { if ((options & VirtualPathOptions.AllowAppRelativePath) == 0) { throw new ArgumentException($"virtualPath {virtualPath} allow appRelativePath"); } virtualPathObject._appRelativeVirtualPath = virtualPath; } else { // It's possible for the path to become absolute after calling Reduce, // even though it started with "~/". e.g. if the app is "/app" and the path is // "~/../hello.aspx", it becomes "/hello.aspx", which is absolute if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { throw new ArgumentException($"virtualPath {virtualPath} allow AbsolutePath"); } virtualPathObject._virtualPath = virtualPath; } } else { if (virtualPath[0] != '/') { if ((options & VirtualPathOptions.AllowRelativePath) == 0) { throw new ArgumentException($"virtualPath {virtualPath} allow relativePath"); } // Don't Reduce relative paths, since the Reduce method is broken (e.g. "../foo.aspx" --> "/foo.aspx!") // virtualPathObject._virtualPath = virtualPath; } else { if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { throw new ArgumentException($"virtualPath {virtualPath} allow AbsolutePath"); } if (dot) { virtualPath = UrlPath.ReduceVirtualPath(virtualPath); } virtualPathObject._virtualPath = virtualPath; } } #if DBG virtualPathObject.ValidateState(); #endif return(virtualPathObject); }
/* Canonicalize virtual paths */ public static string AppendTrailingSlash(string virtualPath) { return(UrlPath.AppendSlashToPathIfNeeded(virtualPath)); }
public static unsafe VirtualPath Create(string virtualPath, VirtualPathOptions options) { if (virtualPath != null) { virtualPath = virtualPath.Trim(); } if (string.IsNullOrEmpty(virtualPath)) { if ((options & VirtualPathOptions.AllowNull) == 0) { throw new ArgumentNullException("virtualPath"); } return(null); } bool flag = false; bool flag2 = false; int length = virtualPath.Length; fixed(char *str = ((char *)virtualPath)) { char *chPtr = str; for (int i = 0; i < length; i++) { switch (chPtr[i]) { case '.': flag2 = true; break; case '/': if ((i > 0) && (chPtr[i - 1] == '/')) { flag = true; } break; case '\\': flag = true; break; case '\0': throw new HttpException(System.Web.SR.GetString("Invalid_vpath", new object[] { virtualPath })); } } } if (flag) { if ((options & VirtualPathOptions.FailIfMalformed) != 0) { throw new HttpException(System.Web.SR.GetString("Invalid_vpath", new object[] { virtualPath })); } virtualPath = UrlPath.FixVirtualPathSlashes(virtualPath); } if ((options & VirtualPathOptions.EnsureTrailingSlash) != 0) { virtualPath = UrlPath.AppendSlashToPathIfNeeded(virtualPath); } VirtualPath path = new VirtualPath(); if (UrlPath.IsAppRelativePath(virtualPath)) { if (flag2) { virtualPath = UrlPath.ReduceVirtualPath(virtualPath); } if (virtualPath[0] == '~') { if ((options & VirtualPathOptions.AllowAppRelativePath) == 0) { throw new ArgumentException(System.Web.SR.GetString("VirtualPath_AllowAppRelativePath", new object[] { virtualPath })); } path._appRelativeVirtualPath = virtualPath; return(path); } if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { throw new ArgumentException(System.Web.SR.GetString("VirtualPath_AllowAbsolutePath", new object[] { virtualPath })); } path._virtualPath = virtualPath; return(path); } if (virtualPath[0] != '/') { if ((options & VirtualPathOptions.AllowRelativePath) == 0) { throw new ArgumentException(System.Web.SR.GetString("VirtualPath_AllowRelativePath", new object[] { virtualPath })); } path._virtualPath = virtualPath; return(path); } if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { throw new ArgumentException(System.Web.SR.GetString("VirtualPath_AllowAbsolutePath", new object[] { virtualPath })); } if (flag2) { virtualPath = UrlPath.ReduceVirtualPath(virtualPath); } path._virtualPath = virtualPath; return(path); }
public static VirtualPath Create(string virtualPath, VirtualPathOptions options) { if (virtualPath != null) { virtualPath = virtualPath.Trim(); } if (string.IsNullOrEmpty(virtualPath)) { if ((options & VirtualPathOptions.AllowNull) == 0) { throw new ArgumentNullException("virtualPath"); } return(null); } bool flag = false; bool flag2 = false; int length = virtualPath.Length; { var chPtr = virtualPath; if (chPtr != null) { chPtr = chPtr.Substring(RuntimeHelpers.OffsetToStringData); } for (int i = 0; i < length; i++) { switch (chPtr[i]) { case '\0': { object[] args = new object[] { virtualPath }; throw new HttpException(string.Format("Invalid vpath {0}", args)); } case '.': flag2 = true; break; case '/': if ((i > 0) && (chPtr[i - 1] == '/')) { flag = true; } break; case '\\': flag = true; break; } } } if (flag) { if ((options & VirtualPathOptions.FailIfMalformed) != 0) { object[] objArray2 = new object[] { virtualPath }; throw new HttpException(string.Format("Invalid vpath {0}", objArray2)); } virtualPath = UrlPath.FixVirtualPathSlashes(virtualPath); } if ((options & VirtualPathOptions.EnsureTrailingSlash) != 0) { virtualPath = UrlPath.AppendSlashToPathIfNeeded(virtualPath); } VirtualPath path = new VirtualPath(); if (UrlPath.IsAppRelativePath(virtualPath)) { if (flag2) { virtualPath = UrlPath.ReduceVirtualPath(virtualPath); } if (virtualPath[0] == '~') { if ((options & VirtualPathOptions.AllowAppRelativePath) == 0) { object[] objArray3 = new object[] { virtualPath }; throw new ArgumentException(string.Format("VirtualPath allow app relative path {0}", objArray3)); } path._appRelativeVirtualPath = virtualPath; return(path); } if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { object[] objArray4 = new object[] { virtualPath }; throw new ArgumentException(string.Format("VirtualPath allow absolute path {0}", objArray4)); } path._virtualPath = virtualPath; return(path); } if (virtualPath[0] != '/') { if ((options & VirtualPathOptions.AllowRelativePath) == 0) { object[] objArray5 = new object[] { virtualPath }; throw new ArgumentException(string.Format("VirtualPath allow relative path {0}", objArray5)); } path._virtualPath = virtualPath; return(path); } if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { object[] objArray6 = new object[] { virtualPath }; throw new ArgumentException(string.Format("VirtualPath allow absolute path {0}", objArray6)); } if (flag2) { virtualPath = UrlPath.ReduceVirtualPath(virtualPath); } path._virtualPath = virtualPath; return(path); }
public static VirtualPath Create(string virtualPath, VirtualPathOptions options) { if (virtualPath != null) { virtualPath = virtualPath.Trim(); } if (string.IsNullOrEmpty(virtualPath)) { if ((options & VirtualPathOptions.AllowNull) == 0) { throw new ArgumentNullException("virtualPath"); } return(null); } if (ContainsIllegalVirtualPathChars(virtualPath)) { throw new HttpException(""); //Resources.GetString("Invalid_vpath", new object[] { _virtualPath })); } string normalizedVirtualPath = UrlPath.FixVirtualPathSlashes(virtualPath); if (((options & VirtualPathOptions.FailIfMalformed) != 0) && !object.ReferenceEquals(virtualPath, normalizedVirtualPath)) { throw new HttpException(""); //"Invalid virtual path ", _virtualPath })); } virtualPath = normalizedVirtualPath; if ((options & VirtualPathOptions.EnsureTrailingSlash) != 0) { virtualPath = UrlPath.AppendSlashToPathIfNeeded(virtualPath); } VirtualPath path = new VirtualPath(); if (UrlPath.IsAppRelativePath(virtualPath)) { virtualPath = UrlPath.ReduceVirtualPath(virtualPath); if (virtualPath[0] == '~') { if ((options & VirtualPathOptions.AllowAppRelativePath) == 0) { throw new ArgumentException();//Resources.GetString("VirtualPath_AllowAppRelativePath", new object[] { _virtualPath })); } path._appRelativeVirtualPath = virtualPath; return(path); } if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { throw new ArgumentException();//Resources.GetString("VirtualPath_AllowAbsolutePath", new object[] { _virtualPath })); } path._virtualPath = virtualPath; return(path); } if (virtualPath[0] != '/') { if ((options & VirtualPathOptions.AllowRelativePath) == 0) { throw new ArgumentException();//Resources.GetString("VirtualPath_AllowRelativePath", new object[] { _virtualPath })); } path._virtualPath = virtualPath; return(path); } if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) { throw new ArgumentException();//Resources.GetString("VirtualPath_AllowAbsolutePath", new object[] { _virtualPath })); } path._virtualPath = UrlPath.ReduceVirtualPath(virtualPath); return(path); }