Commit 964a4ac8 authored by Andy Barron's avatar Andy Barron
Browse files

Fix #3, bump version

parent 8b971247
[package]
name = "app_dirs"
version = "1.0.0"
version = "1.0.1"
authors = ["Andy Barron <AndrewLBarron@gmail.com>"]
description = "Put your app's data in the right place on every platform"
......
......@@ -13,5 +13,5 @@ https://docs.rs/app_dirs
Add the following to your `Cargo.toml` under `[dependencies]`:
```toml
app_dirs = "^1.0.0"
app_dirs = "^1.0.1"
```
\ No newline at end of file
......@@ -13,7 +13,7 @@ use std;
/// Functions in this library sanitize any characters that could be
/// non-filename-safe from `name` and `author`. The resulting paths will be
/// more human-readable if you stick to **letters, numbers, spaces, hyphens,
/// and underscores** for both properties.
/// underscores, and periods** for both properties.
///
/// The `author` property is currently only used by Windows, as macOS and *nix
/// specifications don't require it. Make sure your `name` string is unique!
......
......@@ -49,7 +49,7 @@ mod tests {
name: "Awesome App".into(),
author: "Dedicated Dev".into(),
};
let path = "/subfolder!/with?/unicode/¡Olé!/";
let path = "/.not-hidden/subfolder!/with?/uni.code/¡Olé!/";
let types = [UserConfig, UserData, UserCache, SharedData, SharedConfig];
for &t in types.iter() {
println!("{:?} data root = {:?}", t, get_data_root(t));
......
......@@ -3,22 +3,25 @@
/// This is used internally to generate app data directories based on app
/// name/author. App developers can use it for consistency when dealing with
/// file system operations.
///
/// Do not apply this function to full paths, as it will sanitize '/' and '\';
/// it should only be used on directory or file names (i.e. path segments).
pub fn sanitized(component: &str) -> String {
let mut buf = String::with_capacity(component.len());
for c in component.chars() {
let n = c as u32;
let is_lower = 'a' as u32 <= n && n <= 'z' as u32;
let is_upper = 'A' as u32 <= n && n <= 'Z' as u32;
for (i, c) in component.chars().enumerate() {
let is_lower = 'a' <= c && c <= 'z';
let is_upper = 'A' <= c && c <= 'Z';
let is_letter = is_upper || is_lower;
let is_number = '0' as u32 <= n && n <= '9' as u32;
let is_number = '0' <= c && c <= '9';
let is_space = c == ' ';
let is_hyphen = c == '-';
let is_underscore = c == '_';
let is_valid = is_letter || is_number || is_space || is_hyphen || is_underscore;
let is_period = c == '.' && i != 0; // Disallow accidentally hidden folders
let is_valid = is_letter || is_number || is_space || is_hyphen || is_underscore || is_period;
if is_valid {
buf.push(c);
} else {
buf.push_str(&format!(",{},", n));
buf.push_str(&format!(",{},", c as u32));
}
}
buf
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment