Skip to content

Commit

Permalink
chore(page): remove duplicate abs
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Jan 11, 2025
1 parent bb0edd6 commit 2eacb11
Show file tree
Hide file tree
Showing 8 changed files with 537 additions and 391 deletions.
850 changes: 528 additions & 322 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider"
version = "2.25.3"
version = "2.25.4"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
66 changes: 3 additions & 63 deletions spider/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,9 @@ impl Page {
if source.starts_with("/_next/static/")
&& source.ends_with("/_ssgManifest.js")
{
if let Some(build_path) = self.abs_path(&source) {
if let Some(build_path) =
base.map(|b| convert_abs_path(&b, &source))
{
let _ = cell.set(build_path.to_string());
}
}
Expand Down Expand Up @@ -2176,15 +2178,6 @@ impl Page {
pub async fn links(&self, _: &RelativeSelectors) -> HashSet<CaseInsensitiveString> {
self.links.to_owned()
}

/// Convert a URL to its absolute path without any fragments or params.
#[inline]
#[cfg(not(feature = "decentralized"))]
fn abs_path(&self, href: &str) -> Option<Url> {
self.get_url_parsed_ref()
.as_ref()
.map(|b| convert_abs_path(b, href))
}
}

/// Get the content with proper encoding. Pass in a proper encoding label like SHIFT_JIS.
Expand Down Expand Up @@ -2292,59 +2285,6 @@ async fn test_status_code() {
assert_eq!(page.status_code.as_u16(), 404);
}

#[tokio::test]
async fn test_abs_path() {
let link_result = "https://choosealicense.com/";
let mut page: Page = build(&link_result, Default::default());

page.set_url_parsed_direct_empty();

assert_eq!(
page.abs_path("?query=keyword").expect("a valid url"),
Url::parse("https://choosealicense.com?query=keyword").expect("a valid url")
);

assert_eq!(
page.abs_path("#query=keyword").expect("a valid url"),
Url::parse("https://choosealicense.com").expect("a valid url")
);

assert_eq!(
page.abs_path("/page").expect("a valid url"),
Url::parse("https://choosealicense.com/page").expect("a valid url")
);

assert_eq!(
page.abs_path("/page?query=keyword").expect("a valid url"),
Url::parse("https://choosealicense.com/page?query=keyword").expect("a valid url")
);
assert_eq!(
page.abs_path("/page#hash").expect("a valid url"),
Url::parse("https://choosealicense.com/page").expect("a valid url")
);
assert_eq!(
page.abs_path("/page?query=keyword#hash")
.expect("a valid url"),
Url::parse("https://choosealicense.com/page?query=keyword").unwrap()
);
assert_eq!(
page.abs_path("#hash").unwrap(),
Url::parse("https://choosealicense.com/").expect("a valid url")
);
assert_eq!(
page.abs_path("tel://+212 3456").unwrap(),
Url::parse("https://choosealicense.com/").expect("a valid url")
);

let mut page: Page = build(&format!("{}index.php", link_result), Default::default());
page.set_url_parsed_direct_empty();

assert_eq!(
page.abs_path("index.html").expect("a valid url"),
Url::parse("https://choosealicense.com/index.html").expect("a valid url")
);
}

#[cfg(all(feature = "time", not(feature = "decentralized")))]
#[tokio::test]
async fn test_duration() {
Expand Down
2 changes: 1 addition & 1 deletion spider_chrome/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_chrome"
version = "2.25.3"
version = "2.25.4"
rust-version = "1.70"
authors = [
"j-mendez <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion spider_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_cli"
version = "2.25.3"
version = "2.25.4"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_transformations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_transformations"
version = "2.25.3"
version = "2.25.4"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_utils"
version = "2.25.3"
version = "2.25.4"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_worker"
version = "2.25.3"
version = "2.25.4"
authors = [
"j-mendez <[email protected]>"
]
Expand Down

0 comments on commit 2eacb11

Please sign in to comment.