Skip to content

Commit

Permalink
fix(core): escape + in package names
Browse files Browse the repository at this point in the history
Fixes #891
  • Loading branch information
fosskers committed Aug 8, 2024
1 parent b170040 commit b0a32c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions rust/aura-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# aura-core

## Unreleased

#### Fixed

- Packages like `libstdc++5` now have their inner `+` escaped before querying the Faur.

## 0.8.1

#### Fixed
Expand Down
30 changes: 25 additions & 5 deletions rust/aura-core/src/faur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ where
F: Fn(&str) -> Result<Vec<Package>, E>,
I: IntoIterator<Item = &'a str>,
{
// FIXME Thu May 5 2022 Use `intersperse` once it stabilises.
let s: String = pkgs.into_iter().collect::<Vec<_>>().join(",");
let s = combine_and_sanitize(pkgs);
let url = format!("{}/packages?names={}", FAUR_URL, s);
fetch(&url)
}
Expand All @@ -99,8 +98,7 @@ where
F: Fn(&str) -> Result<Vec<Package>, E>,
I: IntoIterator<Item = &'a str>,
{
// FIXME Thu May 5 2022 Same as above.
let s: String = terms.into_iter().collect::<Vec<_>>().join(",");
let s = combine_and_sanitize(terms);
let url = format!("{}/packages?names={}&by=desc", FAUR_URL, s);
fetch(&url)
}
Expand All @@ -111,17 +109,39 @@ where
S: AsRef<str>,
F: Fn(&str) -> Result<Vec<Package>, E>,
{
let p = providing.as_ref();
let p = combine_and_sanitize([providing.as_ref()]);
let url = format!("{}/packages?names={}&by=prov", FAUR_URL, p);
fetch(&url)
}

fn combine_and_sanitize<'a, I>(terms: I) -> String
where
I: IntoIterator<Item = &'a str>,
{
// FIXME Thu May 5 2022 Use `intersperse` once it stabilises.
terms
.into_iter()
.collect::<Vec<_>>()
.join(",")
.chars()
// Poor man's URL encoding. This fixes the lookup for packages like `libstdc++5`.
.map(|c| if c == '+' { "%2B".to_string() } else { String::from(c) })
.collect()
}

#[cfg(test)]
mod test {
use super::*;
use std::fs::File;
use std::io::BufReader;

#[test]
fn url_escaping() {
let items = ["libstdc++5"];
let res = combine_and_sanitize(items);
assert_eq!("libstdc%2B%2B5", res);
}

#[test]
fn package_parse() {
let file = File::open("tests/faur.json").unwrap();
Expand Down

0 comments on commit b0a32c8

Please sign in to comment.