This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 19800 - "If the number of bytes in mask is not equal to length, return false" can't ever happen?
Summary: "If the number of bytes in mask is not equal to length, return false" can't e...
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: MIME (show other bugs)
Version: unspecified
Hardware: PC All
: P4 normal
Target Milestone: Unsorted
Assignee: Gordon P. Hemsley
QA Contact: sideshowbarker+mimespec
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-31 18:58 UTC by Ian 'Hixie' Hickson
Modified: 2012-11-01 17:19 UTC (History)
2 users (show)

See Also:


Attachments

Description Ian 'Hixie' Hickson 2012-10-31 18:58:50 UTC
In step 5 of the "Pattern matching algorithm":

   "5. If the number of bytes in mask is not equal to length, return false"

.../length/ is equal to the number of bytes in /pattern/, which had better always be the same length as /mask/!
Comment 1 Gordon P. Hemsley 2012-10-31 19:18:31 UTC
This was a built-in test to prevent against typos in the spec or in the implementation.

I included it as a safety net, but if you think it'd be better without it, I can remove it.
Comment 2 Ian 'Hixie' Hickson 2012-10-31 22:25:22 UTC
It'll cause implementors to add code that has no effect. I recommend commenting it out at best. After all, if the patterns are ever wrong, then you don't want the implementations to skip them, you want them to tell you to fix them!

What I sometimes do is add non-normative statements that work a bit like assertions, e.g. "At this point /length/ will also equal the number of bytes in mask".
Comment 3 Gordon P. Hemsley 2012-11-01 17:19:10 UTC
(In reply to comment #2)
> What I sometimes do is add non-normative statements that work a bit like
> assertions, e.g. "At this point /length/ will also equal the number of bytes
> in mask".

I opted to modify step 4 to read:

"Let length be the number of bytes in pattern, which is equal to the number of bytes in mask."

https://github.com/whatwg/mimesniff/commit/5c0c4c9259c6837837ef575b512fb41d3ff3824a