Skip to content

Commit 7c97b6c

Browse files
committed
Handle mutants
1 parent 1aa7f0e commit 7c97b6c

File tree

1 file changed

+103
-7
lines changed

1 file changed

+103
-7
lines changed

payjoin/src/core/url.rs

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,7 @@ fn parse_path_query_fragment(input: &str) -> (String, Option<String>, Option<Str
399399

400400
if let Some(q_pos) = before_fragment.find('?') {
401401
path.push_str(&before_fragment[..q_pos]);
402-
let q_part = &before_fragment[q_pos + 1..];
403-
if let Some(f_pos) = q_part.find('#') {
404-
query = Some(q_part[..f_pos].to_string());
405-
fragment = Some(q_part[f_pos + 1..].to_string());
406-
} else {
407-
query = Some(q_part.to_string());
408-
}
402+
query = Some(before_fragment[q_pos + 1..].to_string());
409403
} else {
410404
path.push_str(before_fragment);
411405
}
@@ -506,4 +500,106 @@ mod tests {
506500
assert_eq!(url.fragment(), Some("FRAGMENT"));
507501
assert_eq!(url.as_str(), "http://localhost:1234/PATH#FRAGMENT");
508502
}
503+
504+
#[test]
505+
fn test_empty_host_rejected() {
506+
assert!(matches!(Url::parse("http:///path"), Err(ParseError::EmptyHost)));
507+
}
508+
509+
#[test]
510+
fn test_path_segments_mut_push_adds_separator() {
511+
let mut url = Url::parse("http://example.com/base").unwrap();
512+
{
513+
let mut segs = url.path_segments_mut().unwrap();
514+
segs.push("child");
515+
}
516+
assert_eq!(url.path(), "/base/child");
517+
assert_eq!(url.as_str(), "http://example.com/base/child");
518+
}
519+
520+
#[test]
521+
fn test_host_str() {
522+
let url = Url::parse("http://example.com/").unwrap();
523+
assert_eq!(url.host_str(), Some("example.com".to_string()));
524+
}
525+
526+
#[test]
527+
fn test_host_str_ipv4() {
528+
let mut url = Url::parse("http://127.0.0.1/").unwrap();
529+
url.host = Some(Host::Ipv4([192, 168, 1, 1]));
530+
url.rebuild_raw();
531+
assert_eq!(url.host_str(), Some("192.168.1.1".to_string()));
532+
assert!(url.as_str().contains("192.168.1.1"));
533+
}
534+
535+
#[test]
536+
fn test_set_port() {
537+
let mut url = Url::parse("http://example.com/path").unwrap();
538+
url.set_port(Some(9090));
539+
assert_eq!(url.port(), Some(9090));
540+
assert_eq!(url.as_str(), "http://example.com:9090/path");
541+
url.set_port(None);
542+
assert_eq!(url.port(), None);
543+
assert_eq!(url.as_str(), "http://example.com/path");
544+
}
545+
546+
#[test]
547+
fn test_path_segments_root() {
548+
let url = Url::parse("http://example.com/").unwrap();
549+
let segs: Vec<_> = url.path_segments().unwrap().collect();
550+
assert!(segs.is_empty());
551+
552+
let url = Url::parse("http://example.com").unwrap();
553+
let segs: Vec<_> = url.path_segments().unwrap().collect();
554+
assert!(segs.is_empty());
555+
}
556+
557+
#[test]
558+
fn test_set_query() {
559+
let mut url = Url::parse("http://example.com/path").unwrap();
560+
url.set_query(Some("key=value"));
561+
assert_eq!(url.query(), Some("key=value"));
562+
assert_eq!(url.as_str(), "http://example.com/path?key=value");
563+
url.set_query(None);
564+
assert_eq!(url.query(), None);
565+
assert_eq!(url.as_str(), "http://example.com/path");
566+
}
567+
568+
#[test]
569+
fn test_join_dot_segments() {
570+
let base = Url::parse("http://example.com/a/b/c").unwrap();
571+
572+
let joined = base.join("./d").unwrap();
573+
assert_eq!(joined.path(), "/a/b/d");
574+
575+
let joined = base.join("../d").unwrap();
576+
assert_eq!(joined.path(), "/a/d");
577+
}
578+
579+
#[test]
580+
fn test_rebuild_raw_with_userinfo() {
581+
let mut url = Url::parse("http://example.com/").unwrap();
582+
url.username = "user".to_string();
583+
url.rebuild_raw();
584+
assert!(url.as_str().contains("user@"));
585+
assert_eq!(url.as_str(), "http://user@example.com/");
586+
}
587+
588+
#[test]
589+
fn test_parse_query_and_fragment() {
590+
let url = Url::parse("http://example.com/path?q=1#frag").unwrap();
591+
assert_eq!(url.path(), "/path");
592+
assert_eq!(url.query(), Some("q=1"));
593+
assert_eq!(url.fragment(), Some("frag"));
594+
}
595+
596+
#[test]
597+
fn test_has_host() {
598+
let url = Url::parse("http://example.com/").unwrap();
599+
assert!(url.has_host());
600+
601+
let mut url = Url::parse("http://example.com/").unwrap();
602+
url.host = None;
603+
assert!(!url.has_host());
604+
}
509605
}

0 commit comments

Comments
 (0)