Skip to content

Commit 8cb6ea6

Browse files
committed
fix: looking for changes.csv in the correct location
If the path of a URL is missing a trailing slash, the last component was dropped from joining the final path.
1 parent 5925cc9 commit 8cb6ea6

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

common/src/utils/url.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ where
4545
}
4646
}
4747
}
48+
49+
/// Ensure that the path has a trailing slash
50+
pub fn ensure_slash(mut url: Url) -> Url {
51+
if !url.path().ends_with("/") {
52+
let new_path = format!("{}/", url.path());
53+
url.set_path(&new_path);
54+
}
55+
56+
url
57+
}

csaf/src/source/http.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use sha2::{Sha256, Sha512};
1414
use std::{sync::Arc, time::SystemTime};
1515
use time::{OffsetDateTime, format_description::well_known::Rfc2822};
1616
use url::{ParseError, Url};
17+
use walker_common::utils::url::ensure_slash;
1718
use walker_common::{
1819
changes::{self, ChangeEntry, ChangeSource},
1920
fetcher::{self, DataProcessor, Fetcher},
@@ -117,23 +118,15 @@ impl Source for HttpSource {
117118

118119
match discover_context.as_ref() {
119120
DistributionContext::Directory(base) => {
120-
let has_slash = base.to_string().ends_with('/');
121-
122-
let join_url = |mut s: &str| {
123-
if has_slash && s.ends_with('/') {
124-
s = &s[1..];
125-
}
126-
Url::parse(&format!("{base}{s}"))
127-
};
128-
129-
let changes = ChangeSource::retrieve(&self.fetcher, &base.clone()).await?;
121+
let base = ensure_slash(base.clone());
122+
let changes = ChangeSource::retrieve(&self.fetcher, &base).await?;
130123

131124
Ok(changes
132125
.entries
133126
.into_iter()
134127
.map(|ChangeEntry { file, timestamp }| {
135128
let modified = timestamp.into();
136-
let url = join_url(&file)?;
129+
let url = base.join(&file)?;
137130

138131
Ok::<_, ParseError>(DiscoveredAdvisory {
139132
context: discover_context.clone(),

0 commit comments

Comments
 (0)