Repository: microsoft/garnet
File: libs/server/SessionParseStateExtensions.cs (C#)

Code before:
        /// Parse client name from parse state at specified index.
        /// </summary>
        /// <param name="parseState">The parse state</param>
        /// <param name="idx">The argument index</param>
        /// <param name="clientName">Client name</param>
        /// <returns>True if value parsed successfully</returns>
        internal static bool TryGetClientName(this SessionParseState parseState, int idx, out string clientName)
        {
            clientName = parseState.GetString(idx);

            if (string.IsNullOrEmpty(clientName))
            {
                return true;
            }

            foreach (var c in clientName)
            {
                if (c < 33 || c > 126)
                {
                    return false;
                }
            }

            return true;
        }

        /// <summary>
        /// Parse client type from parse state at specified index
        /// </summary>
        /// <param name="parseState">The parse state</param>
        /// <param name="idx">The argument index</param>
        /// <param name="value">Parsed value</param>
        /// <returns>True if value parsed successfully</returns>
        public static bool TryGetClientType(this SessionParseState parseState, int idx, out ClientType value)
        {
            value = ClientType.Invalid;
            var sbArg = parseState.GetArgSliceByRef(idx).ReadOnlySpan;

            if (sbArg.EqualsUpperCaseSpanIgnoringCase("NORMAL"u8))
                value = ClientType.NORMAL;
            else if (sbArg.EqualsUpperCaseSpanIgnoringCase("MASTER"u8))
                value = ClientType.MASTER;
            else if (sbArg.EqualsUpperCaseSpanIgnoringCase("REPLICA"u8))
                value = ClientType.REPLICA;
            else if (sbArg.EqualsUpperCaseSpanIgnoringCase("PUBSUB"u8))
                value = ClientType.PUBSUB;
            else if (sbArg.EqualsUpperCaseSpanIgnoringCase("SLAVE"u8))
                value = ClientType.SLAVE;

            return value != ClientType.Invalid;
        }

Review comment (suggestion):
This doesn't seem equivalent to the condition you removed at the caller. Is this an improvement?
Why don't you use the conditions that you removed at the caller? i.e. name.Contains(' ');
Otherwise, add some comments explaining what is not allowed.

Code after:
        /// Parse client name from parse state at specified index.
        /// </summary>
        /// <param name="parseState">The parse state</param>
        /// <param name="idx">The argument index</param>
        /// <param name="clientName">Client name</param>
        /// <returns>True if value parsed successfully</returns>
        internal static bool TryGetClientName(this SessionParseState parseState, int idx, out string clientName)
        {
            clientName = parseState.GetString(idx);

            if (clientName == null)
            {
                return false;
            }

            // Reference allows clearing client name
            if (clientName == string.Empty)
            {
                return true;
            }

            // Client names cannot contain spaces, newlines or special characters.
            // We limit names to printable characters excluding space.
            foreach (var c in clientName)
            {
                if (c < 33 || c > 126)
                {
                    return false;
                }
            }

            return true;
        }

        /// <summary>
        /// Parse client type from parse state at specified index
        /// </summary>
        /// <param name="parseState">The parse state</param>
        /// <param name="idx">The argument index</param>
        /// <param name="value">Parsed value</param>
        /// <returns>True if value parsed successfully</returns>
        public static bool TryGetClientType(this SessionParseState parseState, int idx, out ClientType value)
        {
            value = ClientType.Invalid;
            var sbArg = parseState.GetArgSliceByRef(idx).ReadOnlySpan;

            if (sbArg.EqualsUpperCaseSpanIgnoringCase("NORMAL"u8))
                value = ClientType.NORMAL;
            else if (sbArg.EqualsUpperCaseSpanIgnoringCase("MASTER"u8))
                value = ClientType.MASTER;
            else if (sbArg.EqualsUpperCaseSpanIgnoringCase("REPLICA"u8))