caelum / restfulie

CRUD through HTTP is a good step forward to using resources and becoming RESTful. Another step further into it is to make use of hypermedia-based services and the Restfulie gem allows you to do it very quickly.
Other
393 stars 43 forks source link

Certain accept headers crash restfulie #83

Closed dotnetchris closed 12 years ago

dotnetchris commented 12 years ago

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");
        }
dotnetchris commented 12 years ago

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

dotnetchris commented 12 years ago

Moved to restfulie.net