public static CreateFromUnencodedString ( string unencoded, bool strictlyTreatAsEncoded = false ) : |
||
unencoded | string | |
strictlyTreatAsEncoded | bool | |
return |
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);
}
public static string GetPleaseClickHereForHelpMessage(string pathToProblemFile) { var template2 = LocalizationManager.GetString("Common.ClickHereForHelp", "Please click [here] to get help from the Bloom support team.", "[here] will become a link. Keep the brackets to mark the translated text that should form the link."); var pattern = new Regex(@"\[(.*)\]"); if (!pattern.IsMatch(template2)) { // If the translator messed up and didn't mark the bit that should be the hot link, we'll make the whole sentence hot. // So it will be something like "Please click here to get help from the Bloom support team", and you can click anywhere // on the sentence. template2 = "[" + template2 + "]"; } // If we leave backslashes in here, json will fail to parse it later. It works fine with forward slashes, even on Windows. pathToProblemFile = pathToProblemFile.Replace("\\", "/"); var part2 = pattern.Replace(template2, $"<a href='/bloom/api/teamCollection/reportBadZip?file={UrlPathString.CreateFromUnencodedString(pathToProblemFile).UrlEncoded}'>$1</a>"); return(part2); }