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 19802 - The media type sniffing algorithm always returns the specified type
Summary: The media type sniffing algorithm always returns the specified type
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: MIME (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: Unsorted
Assignee: Gordon P. Hemsley
QA Contact: sideshowbarker+mimespec
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-31 19:08 UTC by Ian 'Hixie' Hickson
Modified: 2012-11-04 16:23 UTC (History)
2 users (show)

See Also:


Attachments

Description Ian 'Hixie' Hickson 2012-10-31 19:08:25 UTC
The media type sniffing algorithm always returns the specified type. Regardless of what sub-algorithms it calls, the last thing it does is always "the actual media type is the specified media type".
Comment 1 Gordon P. Hemsley 2012-10-31 19:34:46 UTC
I haven't quite figured out the logistics of the cascade yet, but "abort these steps" is intended to refer to the "media type sniffing algorithm", not the individual sub-algorithms, as they are all actually part of the same algorithm. (They are "private" methods, if you will.)

In the case of algorithms that can be called directly ("public"), I use "return" to indicate their outcome.

If there's a better way of indicating this, let me know.
Comment 2 Ian 'Hixie' Hickson 2012-10-31 22:20:49 UTC
"Abort the algorithm that invoked this one", maybe. Or return a value and let the caller abort if a useful value was returned. Or have the parent call this one and immediately abort. Or have the parent call this one, and have all subsequent steps in the parent algorithm start with "Otherwise" so they don't get invoked if this one did. Or some such.

But why make them private? The HTML spec invokes some of them directly, which seems like the simple way to keep this understandable.
Comment 3 Gordon P. Hemsley 2012-11-01 14:31:35 UTC
(In reply to comment #2)
> "Abort the algorithm that invoked this one", maybe. Or return a value and
> let the caller abort if a useful value was returned. Or have the parent call
> this one and immediately abort. Or have the parent call this one, and have
> all subsequent steps in the parent algorithm start with "Otherwise" so they
> don't get invoked if this one did. Or some such.
> 
> But why make them private? The HTML spec invokes some of them directly,
> which seems like the simple way to keep this understandable.

Well, IMO, it's much easier to maintain a single table for each section and then have the sub-algorithms that need multiple tables call the sub-algorithms. This reduces data duplication and lowers the risk of making a mistake.

But all the sub-algorithms are intended to be part of the main sniffing algorithm. The fact that you cannot call them directly is a feature, not a bug. That's why I introduced the concept of flags in the main algorithm—so that you can get the same functionality when you are forced to call the main algorithm.
Comment 4 Ian 'Hixie' Hickson 2012-11-01 22:34:41 UTC
Having common tables is fine, but I think it's wrong to view this as one algorithm. It's obviously not one algorithm if the only thing that algorithm does is decide which actual algorithm to use, and the only common part is some minor text about how to buffer incoming data...
Comment 5 Gordon P. Hemsley 2012-11-04 16:23:59 UTC
I've separated the match tables into a separate section so that they can be called from both the main sniffing algorithm and the individual sniffing algorithms.

As a result, I've been able to rearrange the main sniffing algorithm so that it aborts before the last step if it has determined a sniffed media type.

So I think this is fixed.