Only use oembed on YT video links (fixes
@@ -39,6 +39,9 @@ impl Default for Quirks {
// See https://stackoverflow.com/a/19377429/270334
pattern: Regex::new(r"^(https?://)?(www\.)?(youtube\.com|youtu\.?be)").unwrap(),
rewrite: |request| {
+ if request.url().path() != "/watch" {
+ return request;
+ }
let mut out = request;
let original_url = out.url();
let urlencoded: String =
@@ -89,7 +92,7 @@ mod tests {
}
#[test]
- fn test_youtube_request() {
+ fn test_youtube_video_request() {
let orig = Url::parse("https://www.youtube.com/watch?v=NlKuICiT470&list=PLbWDhxwM_45mPVToqaIZNbZeIzFchsKKQ&index=7").unwrap();
let request = Request::new(Method::GET, orig);
let quirks = Quirks::default();
@@ -99,6 +102,16 @@ mod tests {
assert_eq!(modified.method(), Method::GET);
}
+ #[test]
+ fn test_non_video_youtube_url_untouched() {
+ let orig = Url::parse("https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA").unwrap();
+ let request = Request::new(Method::GET, orig.clone());
+ let quirks = Quirks::default();
+ let modified = quirks.apply(request);
+ assert_eq!(modified.url(), &orig);
+ assert_eq!(modified.method(), Method::GET);
+ }
+
#[test]
fn test_no_quirk_applied() {
let orig = Url::parse("https://endler.dev").unwrap();
