Skip to content

Commit

Permalink
fix(index): encode name like the whatwg spec requires
Browse files Browse the repository at this point in the history
this fixes downloads of .xci/.xcz files in tinfoil
  • Loading branch information
DevYukine committed Feb 14, 2021
1 parent 3356c02 commit a1d428e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::gdrive::FileInfo;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

/// https://url.spec.whatwg.org/#fragment-percent-encode-set
const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');

#[skip_serializing_none]
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -92,7 +95,7 @@ pub struct ParsedFileInfo {
impl ParsedFileInfo {
pub fn new(info: FileInfo) -> ParsedFileInfo {
ParsedFileInfo {
name_encoded: utf8_percent_encode(info.name.as_str(), NON_ALPHANUMERIC).to_string(),
name_encoded: utf8_percent_encode(info.name.as_str(), FRAGMENT).to_string(),
id: info.id,
size: info.size,
name: info.name,
Expand Down

0 comments on commit a1d428e

Please sign in to comment.