Commits

Constantin Veretennicov  committed f6dc57e

Update media range match scoring for wildcard media subtypes (*/* or x/*).

Match does not get extra score for zero parameters if range being matched is of
wildcard kind. For example, "*/*" (or "application/*") now matches both
"application/xml" and "application/xml;type=feed" with the same score.

  • Participants
  • Parent commits fe9c707

Comments (0)

Files changed (2)

File src/CsConneg.MediaRange.cs

                 if (!rhsParams.Any())
                 {
                     // Still some extra score is assigned to the match when
-                    // both lhs and rhs have no parameters at all.
-                    accumulatedScore += 0.01M;
+                    // both lhs and rhs have no parameters at all...
+                    if (this.SubType != "*")
+                        // ...unless lhs is a wildcard range, in which case
+                        // existence or absence of parameters is irrelevant.
+                    {
+                        accumulatedScore += 0.01M;
+                    }
                 }
             }
             else if (paramsAreEqual(lhsParams, rhsParams))

File tests/CsConneg.MediaRangeTests.cs

             any.Match(null);
         }
 
-        [TestCase("*/*", "*/*", 50 + 5 + 0.5 + 0.01)]
-        [TestCase("*/*", "text/*", 50 + 5 + 0.5 + 0.01)]
-        [TestCase("*/*", "text/plain", 50 + 5 + 0.5 + 0.01)]
-        [TestCase("*/*", "text/html", 50 + 5 + 0.5 + 0.01)]
+        [TestCase("*/*", "*/*", 50 + 5 + 0.5)]
+        [TestCase("*/*", "text/*", 50 + 5 + 0.5)]
+        [TestCase("*/*", "text/plain", 50 + 5 + 0.5)]
+        [TestCase("*/*", "text/html", 50 + 5 + 0.5)]
         [TestCase("*/*", "text/html;level=1", 50 + 5 + 0.5)]
         [TestCase("*/*", "text/html;spam=bacon;level=1", 50 + 5 + 0.5)]
         [TestCase("*/*", "text/html;level=1;spam=eggs", 50 + 5 + 0.5)]
         //
         [TestCase("text/*", "*/*", 0)]
-        [TestCase("text/*", "text/*", 100 + 5 + 0.5 + 0.01)]
-        [TestCase("text/*", "text/plain", 100 + 5 + 0.5 + 0.01)]
-        [TestCase("text/*", "text/html", 100 + 5 + 0.5 + 0.01)]
+        [TestCase("text/*", "text/*", 100 + 5 + 0.5)]
+        [TestCase("text/*", "text/plain", 100 + 5 + 0.5)]
+        [TestCase("text/*", "text/html", 100 + 5 + 0.5)]
         [TestCase("text/*", "text/html;level=1", 100 + 5 + 0.5)]
         [TestCase("text/*", "text/html;spam=bacon;level=1", 100 + 5 + 0.5)]
         [TestCase("text/*", "text/html;level=1;spam=eggs", 100 + 5 + 0.5)]