Skip to content

Commit

Permalink
chore(page): add safe char handling extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Nov 9, 2024
1 parent 62e5807 commit 1b2c556
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 33 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.13.6"
version = "2.13.7"
authors = [
"j-mendez <jeff@spider.cloud>"
]
Expand Down
33 changes: 12 additions & 21 deletions spider/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,17 @@ pub fn push_link<A: PartialEq + Eq + std::hash::Hash + From<String>>(
let hchars = abs.path();

if let Some(position) = hchars.rfind('.') {
let resource_ext = &hchars[position + 1..hchars.len()];
let hlen = hchars.len();
let has_asset = hlen - position;

if !ONLY_RESOURCES.contains::<CaseInsensitiveString>(&resource_ext.into()) {
can_process = false;
if has_asset >= 3 {
let next_position = position + 1;

if !ONLY_RESOURCES
.contains::<CaseInsensitiveString>(&hchars[next_position..].into())
{
can_process = false;
}
}
}

Expand Down Expand Up @@ -673,15 +680,7 @@ impl Page {
let href = auto_encode_bytes(&matched.as_bytes())
.replace(r#"\u002F"#, "/");

fn get_last_segment(path: &str) -> &str {
if let Some(pos) = path.rfind('/') {
&path[pos + 1..]
} else {
path
}
}

let last_segment = get_last_segment(&href);
let last_segment = crate::utils::get_last_segment(&href);

// we can pass in a static map of the dynamic SSG routes pre-hand, custom API endpoint to seed, or etc later.
if !(last_segment.starts_with("[")
Expand Down Expand Up @@ -1385,15 +1384,7 @@ impl Page {
let href = auto_encode_bytes(&matched.as_bytes())
.replace(r#"\u002F"#, "/");

fn get_last_segment(path: &str) -> &str {
if let Some(pos) = path.rfind('/') {
&path[pos + 1..]
} else {
path
}
}

let last_segment = get_last_segment(&href);
let last_segment = crate::utils::get_last_segment(&href);

// we can pass in a static map of the dynamic SSG routes pre-hand, custom API endpoint to seed, or etc later.
if !(last_segment.starts_with("[") && last_segment.ends_with("]")) {
Expand Down
14 changes: 14 additions & 0 deletions spider/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2853,3 +2853,17 @@ pub(crate) fn modify_selectors(
}
}
}

/// Get the last segment path.
pub fn get_last_segment(path: &str) -> &str {
if let Some(pos) = path.rfind('/') {
let next_position = pos + 1;
if next_position < path.len() {
&path[next_position..]
} else {
""
}
} else {
path
}
}
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.13.6"
version = "2.13.7"
rust-version = "1.70"
authors = [
"j-mendez <jeff@spider.cloud>"
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.13.6"
version = "2.13.7"
authors = [
"j-mendez <jeff@spider.cloud>"
]
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.13.6"
version = "2.13.7"
authors = [
"j-mendez <jeff@spider.cloud>"
]
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.13.6"
version = "2.13.7"
authors = [
"j-mendez <jeff@spider.cloud>"
]
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.13.6"
version = "2.13.7"
authors = [
"j-mendez <jeff@spider.cloud>"
]
Expand Down

0 comments on commit 1b2c556

Please sign in to comment.