TrimEnd Token : Am i doing it wrong or is this a bug ?

Topics: Core, Troubleshooting
Jan 27, 2014 at 12:22 PM
Using a simple token like {User.Content.DisplayText.TrimEnd:2}

I would expect to return for a user named "admin" to get "adm".
But it doesnt.


Looking in TextTokens.cs I flipped the parameters in the body of TrimEnd function and it worked as expected.
Should i file as bug or am i doing it wrong ?
  //private static string TrimEnd(string token, string param) {
        //    if (String.IsNullOrEmpty(param)) {
        //        return token;
        //    }

        //    int n;
        //    if (!int.TryParse(param, out n)) {
        //        return token.TrimEnd(param.ToCharArray());
        //    }

        //    n = Math.Max(0, n); // prevent negative numbers
        //    return token.Substring(0, token.Length - n);
        //}

        private static string TrimEnd(string token, string param)
        {
            if (String.IsNullOrEmpty(token))
            {
                return param;
            }

            int n;
            if (!int.TryParse(token, out n))
            {
                return param.TrimEnd(token.ToCharArray());
            }

            n = Math.Max(0, n); // prevent negative numbers
            return param.Substring(0, param.Length - n);
        }
Jan 27, 2014 at 12:39 PM
Edited Jan 27, 2014 at 12:42 PM
Or even simpler just change the positions of parameters in original function signature from
private static string TrimEnd(string token, string param) {}
to
private static string TrimEnd(string param ,string token) {}
to work.
Will file a bug.
https://orchard.codeplex.com/workitem/20455