Implements 26845 and 26846 - updates to Alias validation

[TFS Changeset #65688]
This commit is contained in:
hartvig
2010-04-22 10:27:11 +00:00
parent bb3cb5616f
commit c57e322d2c
4 changed files with 22 additions and 8 deletions

View File

@@ -7,7 +7,8 @@ namespace umbraco.cms.helpers
{
public class Casing
{
public const string VALID_ALIAS_CHARACTERS = "_-abcdefghijklmnopqrstuvwxyz";
public const string VALID_ALIAS_CHARACTERS = "_-abcdefghijklmnopqrstuvwxyz1234567890";
public const string INVALID_FIRST_CHARACTERS = "01234567890";
/// <summary>
/// A helper method to ensure that an Alias string doesn't contains any illegal characters
@@ -26,10 +27,17 @@ namespace umbraco.cms.helpers
if (VALID_ALIAS_CHARACTERS.Contains(currentChar.ToLower()))
{
// check for camel (if previous character is a space, we'll upper case the current one
if (i < aliasLength - 1 && i > 0 && alias.Substring(i - 1, 1) == " ")
currentChar = currentChar.ToUpper();
if (i == 0 && INVALID_FIRST_CHARACTERS.Contains(currentChar.ToLower()))
{
currentChar = "";
}
else
{
if (i < aliasLength - 1 && i > 0 && alias.Substring(i - 1, 1) == " ")
currentChar = currentChar.ToUpper();
safeString.Append(currentChar);
safeString.Append(currentChar);
}
}
}

View File

@@ -94,4 +94,5 @@
<script type="text/javascript">
duplicatePropertyNameAsSafeAlias('ctl00_body_ContentTypeControlNew1_GenericPropertyNew_control_tbName', 'ctl00_body_ContentTypeControlNew1_GenericPropertyNew_control_tbAlias');
checkAlias('ctl00_body_ContentTypeControlNew1_txtAlias');
</script>

View File

@@ -16,7 +16,8 @@ namespace umbraco.presentation.js
Response.Write(String.Format(@"
var UMBRACO_FORCE_SAFE_ALIAS = {0};
var UMBRACO_FORCE_SAFE_ALIAS_VALIDCHARS = '{1}';
", UmbracoSettings.ForceSafeAliases.ToString().ToLower(), Casing.VALID_ALIAS_CHARACTERS));
var UMBRACO_FORCE_SAFE_ALIAS_INVALID_FIRST_CHARS = '{2}';
", UmbracoSettings.ForceSafeAliases.ToString().ToLower(), Casing.VALID_ALIAS_CHARACTERS, Casing.INVALID_FIRST_CHARACTERS));
}

View File

@@ -41,10 +41,14 @@ function safeAlias(alias) {
currentChar = alias.substring(i, i + 1);
if (UMBRACO_FORCE_SAFE_ALIAS_VALIDCHARS.indexOf(currentChar.toLowerCase()) > -1) {
// check for camel (if previous character is a space, we'll upper case the current one
if (i < aliasLength - 1 && i > 0 && alias.substring(i - 1, i) == ' ')
currentChar = currentChar.toUpperCase();
if (i == 0 && UMBRACO_FORCE_SAFE_ALIAS_INVALID_FIRST_CHARS.indexOf(currentChar.toLowerCase()) > 0) {
currentChar = '';
} else {
if (i < aliasLength - 1 && i > 0 && alias.substring(i - 1, i) == ' ')
currentChar = currentChar.toUpperCase();
safeAlias += currentChar;
safeAlias += currentChar;
}
}
}