Compare commits

...

2 Commits

Author SHA1 Message Date
Kienan Stewart 52e66a0372 Don't escape HTML entities in RSS feed output
There is a risk I guess that the the value and diff contain </pre>
which would break the sort of HTML content, but the important part
was to convert the ansi escapes codes rather than escape HTML.

The HTML escaping of the ansi_to_html module is also on a partial
escape, and not very robust. It might be worth using something like
htmlize or html_escape which provide full conversions to both
encoding and decoding HTML entities.
2022-10-07 17:31:30 -04:00
Kienan Stewart 44253beea9 Add guid to items created during updates 2022-10-07 16:41:31 -04:00
1 changed files with 35 additions and 2 deletions

View File

@ -169,10 +169,14 @@ impl Job {
}
let channel = self.channel.as_mut().unwrap();
let update_time = chrono::Utc::now();
let mut guid = rss::Guid::default();
guid.set_permalink(false);
guid.set_value(update_time.timestamp().to_string().as_str());
let item = rss::ItemBuilder::default()
.title(format!("Update to '{}'", self.url))
.link(self.url.clone())
.pub_date(update_time.to_rfc2822())
.guid(Some(guid))
.content(format!(r#"
New content at {}: <br>
<pre class="new-value">
@ -185,8 +189,8 @@ Diff: <br>
</pre>
"#,
update_time.format("%d/%m/%Y %H:%M"),
ansi_to_html::convert_escaped(value).unwrap().as_str(),
ansi_to_html::convert_escaped(diff).unwrap().as_str()
value,
ansi_to_html::convert(diff, false, true).unwrap().as_str()
)
)
.build();
@ -282,4 +286,33 @@ output_file = ./src/job_example.rss
assert_eq!(job.output_file.as_ref().unwrap().to_str().unwrap(), "./src/job_example.rss");
assert_eq!(job.last_value().unwrap(), "Version 1.64.0");
}
#[test]
fn recover_value_from_channel_html_escapes() {
let conf = Conf::get_default_conf();
let output_file = NamedTempFile::new().unwrap();
let mut job_file = NamedTempFile::new().unwrap();
let mut job = Job::new("example", "selector", &conf);
job.output_file = Some(output_file.path().to_path_buf());
writeln!(job_file, "url = example").expect("write failed");
writeln!(job_file, "output_file = {}", output_file.path().display()).expect("write failed");
let value = "Update that contains <a href=\"#\">html</a><br>";
job.update(value, "diff");
let job2 = Job::from_file(job_file.path(), &conf).expect("Failed to read conf file");
assert_eq!(job2.last_value().unwrap(), value);
}
#[test]
fn new_updates_have_different_guids() {
let conf = Conf::get_default_conf();
let mut job = Job::new("example", "selector", &conf);
job.output_file = None;
job.update("update 1", "diff");
std::thread::sleep(Duration::new(1, 0));
job.update("update 2", "diff");
assert!(job.channel.as_ref().unwrap().items[0].guid.is_some());
assert!(job.channel.as_ref().unwrap().items[1].guid.is_some());
assert_ne!(job.channel.as_ref().unwrap().items[0].guid.as_ref().unwrap(),
job.channel.as_ref().unwrap().items[1].guid.as_ref().unwrap());
}
}