meebey / SmartIrc4net

IRC C# Library
http://www.meebey.net/projects/smartirc4net/
Other
127 stars 52 forks source link

Fix PREFIX misparse (closes #854). #11

Closed RavuAlHemio closed 11 years ago

RavuAlHemio commented 11 years ago

Not skipping the leading '(' when splitting on the ')' always makes the modes list longer than the prefix list, which leads to an incorrect null return value.

meebey commented 11 years ago

Fix looks good but this needs some extra care:

            var prefixstr = RawProperties ["PREFIX"];
            if (prefixstr == null) {
                // supports no modes (!)
                return modesList;
            }

            // format: (modes)prefixes
            if (prefixstr [0] != '(') {
                return null;
            }

            var modesPrefixes = prefixstr.Substring(1).Split(')');

The issue is prefixstr can be an empty string or 1 character both woud lead to a IndexOutOfBoundsException, please add to the null check || prefixstr.Length < 2

RavuAlHemio commented 11 years ago

You're right -- and the class is really begging for unit tests anyway. If you could add a unit-test subproject to the SmartIrc4net solution, I'll write them.