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

current_working_dir.file_path returns partial result for paths with '#' in the name #6158

Closed
Syntaxheld opened this issue Sep 18, 2024 · 5 comments
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.

Comments

@Syntaxheld
Copy link

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

wezterm 20240915-153243-2d0c5cdd

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

When the current working directory name contains a hash ('#'), the result of tab.active_pane.current_working_dir.file_path ends before that hash.

To Reproduce

  • use supplied config
  • mkdir 'folder with #tag'
  • cd 'folder with #tag'
  • look at debug overlay

The current_working_dir result will include the whole name, but the current_working_dir.file_path representation will end before the #.

Configuration

wezterm.on('format-window-title', function(tab, pane, tabs, panes, config)
	local cwd = tab.active_pane.current_working_dir
	if not cwd then
		return "W?"
	end

	wezterm.log_info(string.format("%s %s", "CWD:", tab.active_pane.current_working_dir))
	wezterm.log_info(string.format("%s %s", " FP:", tab.active_pane.current_working_dir.file_path))
	
    return cwd.file_path or "W??"
end)

Expected Behavior

file_path should include the hash and the rest of the path name.

Logs

00:32:14.521 INFO logging > lua: CWD: file:///Users/guest/Desktop/path%20#%20slupu
00:32:14.521 INFO logging > lua:  FP: /Users/guest/Desktop/path

Anything else?

No response

@Syntaxheld Syntaxheld added the bug Something isn't working label Sep 18, 2024
@Syntaxheld Syntaxheld changed the title current_working_dir.file_path returns wrong result for paths with '#' in the name current_working_dir.file_path returns partial result for paths with '#' in the name Sep 18, 2024
@loops
Copy link
Contributor

loops commented Sep 20, 2024

Hi Syntaxheld,

The URL parser treats anything after '#' as a fragment. And the same thing happens with everything after '?' being treated as a query.

This could be fixed. But, since the current working directory should always return a nil file_path, what are you trying to do by using .file_path in the first place? What is the situation where this bug is a problem for you?

@Syntaxheld
Copy link
Author

Syntaxheld commented Sep 20, 2024

@loops I stumbled over this as part of a workaround for #6154 ... I wanted the window title to show the working directory of the current tab (/ active pane).

This bug is not a problem for me, since by now I am using user variables to do what I need.

[...] current working directory should always return a nil file_path

Why? Docs say cwd is a URL object, and URL docs say "file_path - decodes the path field and interprets it as a file path".

@wez
Copy link
Owner

wez commented Sep 21, 2024

Sounds like we should avoid using the Url::parse constructor for paths and find a different way to create a url for a path, because there is no reason that this shouldn't work

@wez
Copy link
Owner

wez commented Sep 21, 2024

perhaps https://docs.rs/url/latest/url/struct.Url.html#method.from_file_path
I don't have time to look at this right now, but if someone wanted to jump in, that's probably the direction to go in.

loops added a commit to loops/wezterm that referenced this issue Sep 21, 2024
When referencing the current-working-directory, before
it is set by an OSC 7 escape sequence, we ask the OS
for the correct path.  This path was then being parsed
as a URL; where a "#" or "?" character would be
interpreted as the start of a fragment or query
component of a URL -- which is a mistake.

So this change parses the returned directory as such,
where those characters will be treated as a normal
character in the path.

Nothing is changed for the OSC 7 escape sequence case.
In that case, the application must percent-encode the
path before sending, so that those characters are not
misinterpreted.

As per issue wez#6158 reported by Syntaxheld
loops added a commit to loops/wezterm that referenced this issue Sep 21, 2024
When referencing the current-working-directory, before
it is set by an OSC 7 escape sequence, we ask the OS
for the correct path.  This path was then being parsed
as a URL; where a "#" or "?" character would be
interpreted as the start of a fragment or query
component of a URL -- which is a mistake.

So this change parses the returned directory as such,
where those characters will be treated as a normal
character in the path.

Nothing is changed for the OSC 7 escape sequence case.
In that case, the application must percent-encode the
path before sending, so that those characters are not
misinterpreted.

As per issue wez#6158 reported by Syntaxheld
wez pushed a commit that referenced this issue Sep 21, 2024
When referencing the current-working-directory, before
it is set by an OSC 7 escape sequence, we ask the OS
for the correct path.  This path was then being parsed
as a URL; where a "#" or "?" character would be
interpreted as the start of a fragment or query
component of a URL -- which is a mistake.

So this change parses the returned directory as such,
where those characters will be treated as a normal
character in the path.

Nothing is changed for the OSC 7 escape sequence case.
In that case, the application must percent-encode the
path before sending, so that those characters are not
misinterpreted.

As per issue #6158 reported by Syntaxheld
@wez wez closed this as completed in 9d4a145 Sep 21, 2024
@wez wez added the fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. label Sep 21, 2024
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.
Projects
None yet
Development

No branches or pull requests

3 participants