identity_credential/
utils.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use identity_core::common::Url;

pub(crate) fn url_only_includes_origin(url: &Url) -> bool {
  url.path() == "/" && url.query().is_none() && url.fragment().is_none()
}

#[cfg(test)]
mod tests {
  use super::url_only_includes_origin;
  use identity_core::common::Url;

  #[test]
  fn empty_path_and_root_are_valid_origins() {
    let urls = ["https://example.com", "https://example.com/"];
    for url in urls {
      assert!(url_only_includes_origin(&Url::parse(url).unwrap()));
    }
  }
}