Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly open uris containing spaces #777

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace Terminal.Utils {
public string? sanitize_path (string _path, string shell_location, bool add_file_scheme = true) {
/* Remove trailing whitespace, ensure scheme, substitute leading "~" and "..", remove extraneous "/" */
string scheme = "", path = "";

var parts_scheme = _path.split ("://", 2);
if (parts_scheme.length == 2) {
scheme = parts_scheme[0] + "://";
Expand Down Expand Up @@ -63,7 +62,7 @@ namespace Terminal.Utils {
parts_sep[index] = construct_parent_path (shell_location);
}

var result = escape_uri (scheme + string.joinv (Path.DIR_SEPARATOR_S, parts_sep).replace ("//", "/"));
var result = scheme + string.joinv (Path.DIR_SEPARATOR_S, parts_sep).replace ("//", "/");
return result;
}

Expand Down
16 changes: 11 additions & 5 deletions src/Widgets/TerminalWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -776,21 +776,27 @@ namespace Terminal {
var uris = selection_data.get_uris ();
string path;
File file;

for (var i = 0; i < uris.length; i++) {
file = File.new_for_uri (uris[i]);
if ((path = file.get_path ()) != null) {
uris[i] = Shell.quote (path) + " ";
// Get sanitized unquoted path (Files sends uris that are escaped and quoted)
jeremypw marked this conversation as resolved.
Show resolved Hide resolved
// We do not want the `file://` scheme included
// We assume dropped paths are absolute
file = File.new_for_uri (Utils.sanitize_path (Shell.unquote (uris[i]), "", false));
jeremypw marked this conversation as resolved.
Show resolved Hide resolved
path = file.get_path ();
if (path != null) {
uris[i] = Shell.quote (path) + " ";
} else {
// Ignore unvalid paths
uris[i] = "";
}
}

var uris_s = string.joinv ("", uris);
this.feed_child (uris_s.data);
break;

case DropTargets.STRING:
case DropTargets.TEXT:
var data = selection_data.get_text ();

if (data != null) {
this.feed_child (data.data);
}
Expand Down