Skip to content

Commit

Permalink
Strip .click package name
Browse files Browse the repository at this point in the history
Only allow a conservative selection of characters in the package name.
The Open Store seems to fail to install packages with non-ascii
characters.
  • Loading branch information
timsueberkrueb committed May 28, 2020
1 parent ed45f9b commit d37379b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde_json = "1.0"
hex = "0.4"
blake2 = "0.8"
gettext-rs = "0.4"
deunicode = "1.1"

[build-dependencies]
cpp_build = "0.5"
11 changes: 10 additions & 1 deletion clickable.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"template": "rust",
"builder": "rust",
"kill": "webber",
"dependencies_host": ["pkg-config"],
"dependencies_target": ["libssl-dev"],
"prebuild": "./scripts/get_deps.sh",
"image_setup": {
"run": [
"rustup install 1.43.1",
"rustup default 1.43.1",
"/bin/bash -c 'echo $ARCH'",
"/bin/bash -c \"if [ -d '/usr/lib/arm-linux-gnueabihf' ]; then rustup target add armv7-unknown-linux-gnueabihf; fi\"",
"/bin/bash -c \"if [ -d '/usr/lib/aarch64-linux-gnu' ]; then rustup target add aarch64-unknown-linux-gnu; fi\""
]
},
"ignore": [
"build",
"scripts",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"content-hub": "content-hub.json"
}
},
"version": "0.5.3",
"version": "0.5.4",
"maintainer": "Tim Süberkrüb <[email protected]>",
"framework" : "ubuntu-sdk-16.04"
}
27 changes: 25 additions & 2 deletions src/click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::process::Command;
use blake2::digest::{Input, VariableOutput};
use blake2::VarBlake2s;

use deunicode::deunicode;

const DESKTOP_USER_AGENT: &str =
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.9.9999.999 Safari/537.36";

Expand Down Expand Up @@ -116,7 +118,7 @@ impl Package {
create_tar_gz(&control_tar_gz, &control)?;
create_tar_gz(&data_tar_gz, &data)?;

let click_path = path.join(Path::new(&format!("{}.click", self.name)));
let click_path = path.join(Path::new(&format!("{}.click", self.package_name())));

create_ar(
&click_path,
Expand All @@ -131,6 +133,27 @@ impl Package {
Ok(click_path)
}

fn package_name(&self) -> String {
let stripped_name = deunicode(&self.name)
.chars()
.filter_map(|c|
if ('a'..='z').contains(&c)
|| ('A'..='Z').contains(&c)
|| c.is_digit(10)
|| c == ' ' || c == '-' || c == '.' {
Some(c)
} else {
None
}
)
.collect::<String>();
if stripped_name.is_empty() {
"Webapp".to_owned()
} else {
stripped_name
}
}

fn appname(&self) -> String {
let url = url::Url::parse(&self.url).ok();

Expand Down Expand Up @@ -178,7 +201,7 @@ impl Package {
.filter_map(|c| {
if c == '/' || c == '.' || c == '_' {
Some('-')
} else if ('a'..'z').contains(&c) || c.is_digit(10) {
} else if ('a'..='z').contains(&c) || c.is_digit(10) {
Some(c)
} else {
None
Expand Down

0 comments on commit d37379b

Please sign in to comment.