-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from feed-rs/pluggable-id-generation
Pluggable ID generation
- Loading branch information
Showing
5 changed files
with
145 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<rss version="2.0"> | ||
<channel> | ||
<title>Latest Linux Kernel Versions</title> | ||
<link>http://www.kernel.org</link> | ||
<description>Latest Linux Kernel Versions</description> | ||
<lastBuildDate>Fri, 08 May 2020 11:11:02 -0000</lastBuildDate> | ||
<item> | ||
<title>5.7-rc4: mainline</title> | ||
<link>http://www.kernel.org/</link> | ||
<description> | ||
<table> | ||
<tr><th align="right">Version:</th><td><strong>5.7-rc4</strong> | ||
(mainline)</td></tr> | ||
<tr><th align="right">Released:</th><td>2020-05-03</td></tr> | ||
|
||
<tr><th align="right">Source:</th><td><a | ||
href="https://git.kernel.org/torvalds/t/linux-5.7-rc4.tar.gz">linux-5.7-rc4.tar.gz</a></td></tr> | ||
<tr><th align="right">Patch:</th><td><a | ||
href="https://git.kernel.org/torvalds/p/v5.7-rc4/v5.6">full</a> (<a | ||
href="https://git.kernel.org/torvalds/p/v5.7-rc4/v5.7-rc3">incremental</a>)</td></tr> | ||
</table> | ||
</description> | ||
<pubDate>Sun, 03 May 2020 21:56:15 -0000</pubDate> | ||
<guid isPermaLink="false">kernel.org,mainline,5.7-rc4,2020-05-03</guid> | ||
</item> | ||
</channel> | ||
</rss> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::model::Link; | ||
use crate::parser; | ||
use crate::parser::{generate_id_from_link_and_title, util}; | ||
use crate::util::test; | ||
|
||
// Regression test for the default ID generator | ||
#[test] | ||
fn id_generator_default() { | ||
let test_data = test::fixture_as_raw("rss2/rss_2.0_kdist.xml"); | ||
let feed = parser::parse(test_data.as_slice()).unwrap(); | ||
assert_eq!("354331764be7571efc15c7a1bad13d54", feed.id); | ||
} | ||
|
||
// Custom implementation providing backward compatibility with v0.2 | ||
#[test] | ||
fn id_generator_v0_2() { | ||
let test_data = test::fixture_as_raw("rss2/rss_2.0_kdist.xml"); | ||
|
||
// Custom ID that trims URLs etc | ||
let feed = parser::Builder::new() | ||
.id_generator(|links, title, _uri| { | ||
// If we have a link without relative components, use that | ||
if let Some(link) = links.iter().find(|l| l.rel.is_none()) { | ||
// Trim the trailing slash if it exists | ||
let mut link = Link::new(link.href.clone(), None); | ||
if link.href.ends_with('/') { | ||
link.href.pop(); | ||
} | ||
|
||
generate_id_from_link_and_title(&link, title) | ||
} else { | ||
util::uuid_gen() | ||
} | ||
}) | ||
.build() | ||
.parse(test_data.as_slice()) | ||
.unwrap(); | ||
assert_eq!("7edcf1fbe86570753646f6eb75db4d55", feed.id); | ||
} | ||
|
||
// Verifies failure uncovered by fuzzing is now fixed | ||
#[test] | ||
fn fuzz_parse() { | ||
let data: Vec<u8> = vec![ | ||
0xdb, 0x3b, 0x3c, 0x66, 0x65, 0x65, 0x64, 0x3e, 0x00, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x3c, 0x1b, 0x3b, 0x64, 0x22, 0x22, 0x0d, 0x78, 0x6d, 0x6c, 0x3a, | ||
0x62, 0x61, 0x73, 0x65, 0x0d, 0x0d, 0x3d, 0x0a, 0x22, 0x0a, 0x0d, 0x0a, 0x0a, 0x0d, 0x66, 0x69, 0x6c, 0x65, 0x3a, 0xff, 0x3b, 0xbf, 0x5b, 0xbf, 0xbf, | ||
0xbc, 0xff, 0xff, 0x0a, 0x53, 0x53, 0x2b, 0x78, 0x3b, 0x22, 0x3c, 0x64, 0x3e, 0x2b, 0x00, 0x00, 0x2b, 0x3c, 0xdb, 0x3b, 0x32, 0x65, 0x64, 0x22, 0x22, | ||
0x0d, 0x78, 0x6d, 0x6c, 0x3a, 0x62, 0x61, 0x73, 0x65, 0x0d, 0x0d, 0x3d, 0x22, 0x75, 0x7c, 0x3f, 0x0a, 0x34, 0x0a, 0xff, 0x22, 0x34, 0x3a, 0xb5, 0x2f, | ||
0x3c, 0x66, 0x65, 0x64, 0x3e, 0x2b, 0x3c, 0xdb, 0x3b, 0x32, 0x65, 0x0d, 0x78, 0x6d, 0x6c, 0x3a, 0x62, 0x61, 0x73, 0x65, 0x0d, 0x0d, 0x3d, 0x22, 0x2e, | ||
0x2e, 0x3f, 0x0a, 0x3c, 0x3f, 0xff, 0x22, 0x34, 0x3a, 0xb5, 0x2f, 0x2f, 0xff, 0xff, 0xfe, 0x01, 0xdb, 0x3b, 0x3c, 0x66, 0x65, | ||
]; | ||
|
||
let result = parser::parse(data.as_slice()); | ||
assert!(result.is_err()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters