Commits

Bryan Fink  committed 3e6cd84

handle strange "q" value format in Accept header from FeedBurner client (thanks, Marc)

  • Participants
  • Parent commits 8953dc6

Comments (0)

Files changed (1)

File src/webmachine_util.erl

 		    QVal = case Val of
 			"1" ->
 			    1;
+                        [$.|_] ->
+                            %% handle strange FeedBurner Accept
+                            list_to_float([$0|Val]); 
 			_ -> list_to_float(Val)
 		    end,
 		    {QVal, Type, Rest ++ Acc};
             case PrioStr of
                 "0" -> {0.0, Choice};
                 "1" -> {1.0, Choice};
+                [$.|_] ->
+                    %% handle strange FeedBurner Accept
+                    {list_to_float([$0|PrioStr]), Choice};
                 _ -> {list_to_float(PrioStr), Choice}
             end;
         {Choice} ->
       || I <- ShouldMatch ],
     [ ?assertEqual(none, choose_media_type([Provided], I))
       || I <- WantNone ].
+
+choose_media_type_qval_test() ->
+    Provided = ["text/html", "image/jpeg"],
+    HtmlMatch = ["image/jpeg;q=0.5, text/html",
+                 "text/html, image/jpeg; q=0.5",
+                 "text/*; q=0.8, image/*;q=0.7",
+                 "text/*;q=.8, image/*;q=.7"], %% strange FeedBurner format
+    JpgMatch = ["image/*;q=1, text/html;q=0.9",
+                "image/png, image/*;q=0.3"],
+    [ ?assertEqual("text/html", choose_media_type(Provided, I))
+      || I <- HtmlMatch ],
+    [ ?assertEqual("image/jpeg", choose_media_type(Provided, I))
+      || I <- JpgMatch ].