Skip to content

Commit e7eb709

Browse files
AlexMikhalevclaude
andauthored
fix(automata): correct URL validation logic in AutomataPath::from_remote() (#733)
The condition used `||` (OR) instead of `&&` (AND), causing De Morgan's law to make the check always evaluate to true -- rejecting all URLs including valid http:// and https:// ones. Also adds scheme-specific prefixes (http:// and https://) instead of bare "http"/"https". Fixes #139 Co-authored-by: Terraphim AI <noreply@anthropic.com>
1 parent 32a8e6d commit e7eb709

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

  • crates/terraphim_automata/src

crates/terraphim_automata/src/lib.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl Display for AutomataPath {
246246
impl AutomataPath {
247247
/// Create a new AutomataPath from a URL
248248
pub fn from_remote(url: &str) -> Result<Self> {
249-
if !url.starts_with("http") || !url.starts_with("https") {
249+
if !url.starts_with("http://") && !url.starts_with("https://") {
250250
return Err(TerraphimAutomataError::Dict(format!(
251251
"Invalid URL scheme. Only `http` and `https` are supported right now. Got {}",
252252
url
@@ -625,4 +625,46 @@ mod tests {
625625
let result = load_thesaurus_from_json(invalid_json);
626626
assert!(result.is_err());
627627
}
628+
629+
#[test]
630+
fn test_from_remote_accepts_https() {
631+
let result = AutomataPath::from_remote("https://example.com/thesaurus.json");
632+
assert!(result.is_ok());
633+
match result.unwrap() {
634+
AutomataPath::Remote(url) => {
635+
assert_eq!(url, "https://example.com/thesaurus.json");
636+
}
637+
AutomataPath::Local(_) => panic!("Expected Remote variant"),
638+
}
639+
}
640+
641+
#[test]
642+
fn test_from_remote_accepts_http() {
643+
let result = AutomataPath::from_remote("http://example.com/thesaurus.json");
644+
assert!(result.is_ok());
645+
match result.unwrap() {
646+
AutomataPath::Remote(url) => {
647+
assert_eq!(url, "http://example.com/thesaurus.json");
648+
}
649+
AutomataPath::Local(_) => panic!("Expected Remote variant"),
650+
}
651+
}
652+
653+
#[test]
654+
fn test_from_remote_rejects_ftp() {
655+
let result = AutomataPath::from_remote("ftp://example.com/thesaurus.json");
656+
assert!(result.is_err());
657+
}
658+
659+
#[test]
660+
fn test_from_remote_rejects_file_path() {
661+
let result = AutomataPath::from_remote("/tmp/thesaurus.json");
662+
assert!(result.is_err());
663+
}
664+
665+
#[test]
666+
fn test_from_remote_rejects_empty() {
667+
let result = AutomataPath::from_remote("");
668+
assert!(result.is_err());
669+
}
628670
}

0 commit comments

Comments
 (0)