refactor: cleanup logic to get path from protocol req url, closes #4132 (#4192)

This commit is contained in:
Lucas Fernandes Nogueira
2022-05-23 05:37:50 -07:00
committed by GitHub
parent cdfa625511
commit 43daeafd73
3 changed files with 12 additions and 9 deletions

View File

@@ -504,9 +504,9 @@ impl<R: Runtime> WindowManager<R> {
let parsed_path = Url::parse(request.uri())?;
let filtered_path = &parsed_path[..Position::AfterPath];
#[cfg(target_os = "windows")]
let path = filtered_path.replace("asset://localhost/", "");
let path = filtered_path.trim_start_matches("asset://localhost/");
#[cfg(not(target_os = "windows"))]
let path = filtered_path.replace("asset://", "");
let path = filtered_path.trim_start_matches("asset://");
let path = percent_encoding::percent_decode(path.as_bytes())
.decode_utf8_lossy()
.to_string();
@@ -829,8 +829,8 @@ impl<R: Runtime> WindowManager<R> {
// ignore query string and fragment
.next()
.unwrap()
.to_string()
.replace("tauri://localhost", "");
.trim_start_matches("tauri://localhost")
.to_string();
let asset = manager.get_asset(path)?;
let mut builder = HttpResponseBuilder::new()
.header("Access-Control-Allow-Origin", &window_origin)
@@ -1366,15 +1366,15 @@ fn on_menu_event<R: Runtime>(window: &Window<R>, event: &MenuEvent) -> crate::Re
}
#[cfg(feature = "isolation")]
fn request_to_path(request: &tauri_runtime::http::Request, replace: &str) -> String {
fn request_to_path(request: &tauri_runtime::http::Request, base_url: &str) -> String {
let mut path = request
.uri()
.split(&['?', '#'][..])
// ignore query string
.next()
.unwrap()
.to_string()
.replace(replace, "");
.trim_start_matches(base_url)
.to_string();
if path.ends_with('/') {
path.pop();

View File

@@ -2722,6 +2722,9 @@ name = "semver"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4"
dependencies = [
"serde",
]
[[package]]
name = "semver-parser"

View File

@@ -44,9 +44,9 @@ fn main() {
let mut response = ResponseBuilder::new();
// get the wanted path
#[cfg(target_os = "windows")]
let path = request.uri().replace("stream://localhost/", "");
let path = request.uri().trim_start_matches("stream://localhost/");
#[cfg(not(target_os = "windows"))]
let path = request.uri().replace("stream://", "");
let path = request.uri().trim_start_matches("stream://");
let path = percent_encoding::percent_decode(path.as_bytes())
.decode_utf8_lossy()
.to_string();