Repository navigation
Issue #7382 Use descriptive enums instead of booleans for MIMEClassifier::classifer - #7447
Conversation
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @SimonSapin (or someone else) soon. |
|
Huh; the original issue was actually filed about the boolean arguments to the classify function (which ironically weren't touched in this PR). I'll need to think about whether these changes are also worthwhile improvements! |
|
Oh I see, you wanted to swap out https://github.com/ddrmanxbxfr/servo/blob/master/components/net/mime_classifier.rs#L29 For a ENUM too ? While having the hands in refactoring this I could undergo with adding a ENUM such as MIMEClassifyOptions which could include the check_for_apache_bug and no_sniff checks ? This way we'll be able to drop out both booleans and add more check later if needed. If it seems a sane idea please confirm and i'll improve it quickly :) Thanks! |
|
A MIMEClassifyOptions bitfield (http://mxr.mozilla.org/servo/source/components/gfx/font.rs#102) would work, but I think I would prefer two separate enum arguments instead. |
|
Hi JDM, I've added the following so we get it right : Thanks for looking into it, |
|
☔ The latest upstream changes (presumably #7454) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Just rebased and squashed the fixup together. It should help for merge :). Thanks for looking into it. |
|
☔ The latest upstream changes (presumably #7499) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@jdm ping ? Just rebased a 2nd time against upstream/master. |
|
Sorry about the delay. I'll review this by Tuesday at the latest (Monday is a holdiay). |
|
-S-awaiting-review +S-needs-code-changes Reviewed 4 of 4 files at r1, 1 of 1 files at r2. components/net/mime_classifier.rs, line 17 [r1] (raw file): components/net/mime_classifier.rs, line 22 [r1] (raw file): components/net/mime_classifier.rs, line 26 [r1] (raw file): components/net/mime_classifier.rs, line 31 [r1] (raw file): components/net/mime_classifier.rs, line 47 [r1] (raw file): components/net/mime_classifier.rs, line 56 [r1] (raw file): MIMEMediaType:Html =>
//Implied in section 7.3, but flow is not clear
self.feeds_classifier.classify(...)components/net/mime_classifier.rs, line 103 [r1] (raw file): components/net/mime_classifier.rs, line 130 [r1] (raw file): components/net/mime_classifier.rs, line 132 [r1] (raw file): let should_sniff_scriptable = no_sniff_flag == MIMENoSniffFlag::OFF;
let sniffed = if should_sniff_scriptable {
self.scriptable_classifier.classify(data)
} else {
None
};
sniffed.or_else(...)This will require adding components/net/mime_classifier.rs, line 142 [r1] (raw file): components/net/resource_task.rs, line 75 [r1] (raw file): components/net/resource_task.rs, line 107 [r1] (raw file): tests/unit/net/mime_classifier.rs, line 40 [r1] (raw file): tests/unit/net/mime_classifier.rs, line 79 [r1] (raw file): tests/unit/net/mime_classifier.rs, line 493 [r1] (raw file): Comments from the review on Reviewable.io |
|
Review status: 1 of 5 files reviewed at latest revision, 5 unresolved discussions, some commit checks pending. components/net/mime_classifier.rs, line 47 [r1] (raw file): components/net/mime_classifier.rs, line 56 [r1] (raw file): I am not quite sure where you want to move this comment. components/net/mime_classifier.rs, line 132 [r1] (raw file): tests/unit/net/mime_classifier.rs, line 493 [r1] (raw file): We had cases where the resource was interpreted as mislabeled / unknown but no test for the flags at on. They were all done with the flags at off even though they are supposed to have the same behavior. If a resource is unknown mimetype OR comes from Apache Bug Flag, need to interpret it as mislabeled. As I read they have case on UTF-8, 16, 16le bom's. Section 7.2 for mislabeled rules.
Comments from the review on Reviewable.io |
|
Review status: 1 of 5 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. components/net/mime_classifier.rs, line 22 [r1] (raw file): It shouldn't be in this enum... I removed it and fixed the original algorithm in the classify function. Fixing the scope of get_media_type. It should be indeed private :). Comments from the review on Reviewable.io |
|
Review status: 2 of 4 files reviewed at latest revision, 3 unresolved discussions, some commit checks pending. tests/unit/net/mime_classifier.rs, line 493 [r1] (raw file): tests/wpt/css-tests/css21_dev/html4/border-left-color-125.htm, line 0 [r3] (raw file): Comments from the review on Reviewable.io |
|
-S-awaiting-review -S-needs-rebase +S-awaiting-answer Reviewed 3 of 3 files at r4. tests/unit/net/mime_classifier.rs, line 536 [r4] (raw file): tests/wpt/css-tests/css21_dev/html4/border-left-color-125.htm, line 0 [r3] (raw file): Comments from the review on Reviewable.io |
…assifier::classifer
… MIMEClassifier::classifer
|
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. tests/unit/net/mime_classifier.rs, line 536 [r4] (raw file): All the tests with Apache Flag ON needs to have a supplied type to trigger it correctly. I should get Application/Octet-Stream from a video/mp4 file when I have the flag at on.... This means I have a bug in my tests regarding apache flag on. While fixing them I found that utf16-be and utf16-le were not responding the good type. We had application/octet-stream instead of text/plain. I fixed them in BinaryOrPlaintextClassifier. I hope it goes ok with If length is greater than or equal to 2 and the first 2 bytes of the resource header are equal to 0xFE 0xFF (UTF-16BE BOM) or 0xFF 0xFE (UTF-16LE BOM), the computed MIME type is "text/plain". Abort these steps. Comments from the review on Reviewable.io |
|
We'll get it right @jdm once it looks ok let me know i'll rebase commits to not polute the git log. |
|
Ping? @jdm |
|
@bors-servo: r+ Reviewed 1 of 1 files at r5, 2 of 2 files at r6. Comments from the review on Reviewable.io |
|
📌 Commit cc44448 has been approved by |
|
⌛ Testing commit cc44448 with merge 8a8204f... |
Issue #7382 Use descriptive enums instead of booleans for MIMEClassifier::classifer Hi guys i've done a small pass of refactor in the MIMEClassifier implementation. (See issue #7382 ) - Moved the predicates to separate functions - Added a mimetype enum so we can compare them easily after calling MIMEClassifier::get_media_type I hope it follows rust good pratices (care it's my first time doing rust). Improvements and tips are welcome :). Thanks for looking at it. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7447) <!-- Reviewable:end -->
|
☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt |

Hi guys i've done a small pass of refactor in the MIMEClassifier implementation. (See issue #7382 )
I hope it follows rust good pratices (care it's my first time doing rust).
Improvements and tips are welcome :).
Thanks for looking at it.