public static UrlPathString CreateFromUnencodedString(string unencoded, bool strictlyTreatAsEncoded=false)
{
unencoded = unencoded.Trim();
// During the refactoring that lead to this class, one code path
// essentially didn't trust that the string was already decoded.
// Assuming that was done for a good reason, that behavior is
// formalized here. It would seem to be a small risk (makes it
// impossible to have, say "%20" in your actual file name).
// However, a '+' in the name is much more likely, and so blindly
// re-encoding is a problem. So the algorithm is that if the
// symbol is ambiguous (like '+'), assume it is unencoded (because that's
// the name of the method) but if it's obviously encoded, then
// decode it.
if(!strictlyTreatAsEncoded && Regex.IsMatch(unencoded,"%[A-Fa-f0-9]{2}"))
unencoded = HttpUtility.UrlDecode(unencoded);
return new UrlPathString(unencoded);
}