caelum/restfulie

Certain accept headers crash restfulie

dotnetchris opened this issue · 2 comments

Accept: text/html,application/xhtml+xml,application/xml;image/png,image/jpeg,image/;q=0.9,/*;q=0.8

This will crash

AcceptHeaderToMediaType
private FormatPlusQualifier ParseFormat(string type)

 if (ContainsQualifier(type))
            {
                var typeInfo = type.Split(';');
                format = typeInfo[0].Trim();
                qualifier = Convert.ToDouble(typeInfo[1].Split('=')[1], new CultureInfo("en-US"));
            }

This gets an instance of "application/xml;image/png" which it then splits at the ; and then tries to resplit on =, however since there is no = at all, typeInfo[1] is out of bounds of the array.

System.IndexOutOfRangeExceptionIndex was outside the bounds of the array.

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Restfulie.Server.Negotiation.AcceptHeaderToMediaType.ParseFormat(String type)
at Restfulie.Server.Negotiation.AcceptHeaderToMediaType.GetMediaType(String acceptHeader)
at Restfulie.Server.ActAsRestfulie.OnActionExecuting(ActionExecutingContext filterContext)

 [TestFixture]
    public class AcceptHeaderToMediaTypeTests
    {

        [Test]
        public void shouldwork()
        {
            var mediaType = acceptHeader.GetMediaType("text/html,application/xhtml+xml,application/xml;image/png,image/jpeg,image/*;q=0.9,*/*;q=0.8");
        }

Any input on this? I don't really understand content negotiation to resolve this properly as opposed to resolving this to just not throw an error

Moved to restfulie.net