fix: skip leading slash for asset protocol, closes #7815 (#7822)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir 2023-09-12 22:57:11 +03:00 committed by GitHub
parent 100d9ede35
commit a68ccaf59a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 11 deletions

View File

@ -0,0 +1,5 @@
---
'tauri': 'patch:bug'
---
Fix `asset` protocol failing to fetch files.

View File

@ -1355,8 +1355,8 @@ impl<R: Runtime> Builder<R> {
/// ```
/// tauri::Builder::default()
/// .register_uri_scheme_protocol("app-files", |_app, request| {
/// let path = request.uri().path().trim_start_matches('/');
/// if let Ok(data) = std::fs::read(path) {
/// // skip leading `/`
/// if let Ok(data) = std::fs::read(&request.uri().path()[1..]) {
/// http::Response::builder()
/// .body(data)
/// .unwrap()
@ -1397,7 +1397,8 @@ impl<R: Runtime> Builder<R> {
/// ```
/// tauri::Builder::default()
/// .register_asynchronous_uri_scheme_protocol("app-files", |_app, request, responder| {
/// let path = request.uri().path().trim_start_matches('/').to_string();
/// // skip leading `/`
/// let path = request.uri().path()[1..].to_string();
/// std::thread::spawn(move || {
/// if let Ok(data) = std::fs::read(path) {
/// responder.respond(

View File

@ -291,8 +291,8 @@ fn parse_invoke_request<R: Runtime>(
#[allow(unused_mut)]
let (parts, mut body) = request.into_parts();
let cmd = parts.uri.path().trim_start_matches('/');
let cmd = percent_encoding::percent_decode(cmd.as_bytes())
// skip leading `/`
let cmd = percent_encoding::percent_decode(parts.uri.path()[1..].as_bytes())
.decode_utf8_lossy()
.to_string();

View File

@ -34,7 +34,8 @@ fn get_response(
scope: &FsScope,
window_origin: &str,
) -> Result<Response<Cow<'static, [u8]>>, Box<dyn std::error::Error>> {
let path = percent_encoding::percent_decode(request.uri().path().as_bytes())
// skip leading `/`
let path = percent_encoding::percent_decode(request.uri().path()[1..].as_bytes())
.decode_utf8_lossy()
.to_string();

View File

@ -3399,7 +3399,7 @@ checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a"
[[package]]
name = "tauri"
version = "2.0.0-alpha.13"
version = "2.0.0-alpha.14"
dependencies = [
"anyhow",
"bytes",
@ -3568,7 +3568,7 @@ dependencies = [
[[package]]
name = "tauri-runtime-wry"
version = "1.0.0-alpha.1"
version = "1.0.0-alpha.2"
dependencies = [
"cocoa 0.24.1",
"gtk",

View File

@ -78,9 +78,8 @@ fn get_stream_response(
request: http::Request<Vec<u8>>,
boundary_id: &Arc<Mutex<i32>>,
) -> Result<http::Response<Vec<u8>>, Box<dyn std::error::Error>> {
// get the file path
let path = request.uri().path();
let path = percent_encoding::percent_decode(path.as_bytes())
// skip leading `/`
let path = percent_encoding::percent_decode(request.uri().path()[1..].as_bytes())
.decode_utf8_lossy()
.to_string();