Auto merge of #7449 - simartin:issue_7393, r=metajack

Issue #7393: Properly sniff mislabeled feeds.

Hi,

This patch is an attempt to fix https://github.com/servo/servo/issues/7393, where the code detecting mislabeled feeds (see https://mimesniff.spec.whatwg.org/#sniffing-a-mislabeled-feed) had spurious space in the URLs we need to match.

Note that my testing (in particular rdf_rss_ko_2.xml) highlighted a flaw in "matches", that failed to check that there were more bytes in the string being checked than in the string we're checking against, which completely broke the whole step 5.2.7.

Thanks in advance for your review.

Cheers,
  Simon

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7449)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-01 11:22:52 -06:00
commit 9f85370885
7 changed files with 52 additions and 6 deletions

View file

@ -434,7 +434,14 @@ fn test_sniff_utf_8_bom() {
#[test]
fn test_sniff_rss_feed() {
// RSS feeds
test_sniff_full(&PathBuf::from("text/xml/feed.rss"), "application", "rss+xml", Some(("text", "html")));
test_sniff_full(&PathBuf::from("text/xml/rdf_rss.xml"), "application", "rss+xml", Some(("text", "html")));
// Not RSS feeds
test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_1.xml"), "text", "html", Some(("text", "html")));
test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_2.xml"), "text", "html", Some(("text", "html")));
test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_3.xml"), "text", "html", Some(("text", "html")));
test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_4.xml"), "text", "html", Some(("text", "html")));
}
#[test]

View file

@ -0,0 +1,7 @@
<!-- Good format for a "RDF feed" -->
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
>
</rdf:RDF>

View file

@ -0,0 +1,7 @@
<!-- Bad format for a "RDF feed" (space between "rdf:" and "RDF") -->
<?xml version="1.0"?>
<rdf: RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
>
</rdf:RDF>

View file

@ -0,0 +1,3 @@
<!-- Bad format for a "RDF feed" (2 missing URLs) -->
<?xml version="1.0"?>
<rdf:RDF/>

View file

@ -0,0 +1,6 @@
<!-- Bad format for a "RDF feed" (one missing URL) -->
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
</rdf:RDF>

View file

@ -0,0 +1,7 @@
<!-- Bad format for a "RDF feed" (unexpected space in first URL) -->
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http: //www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
>
</rdf:RDF>