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

Parsing decodeURI #2013

Closed
wants to merge 1 commit into from
Closed

Parsing decodeURI #2013

wants to merge 1 commit into from

Conversation

SCWR
Copy link

@SCWR SCWR commented Jan 17, 2019

Don't be uris allow characters will be encoded,hence the %% case.
The encoded string is parsed through the decodeURI function

Don't be uris allow characters will be encoded,hence the %% case.
The encoded string is parsed through the decodeURI function
@Stanzilla
Copy link
Member

Can you explain in more detail which problem you are fixing?

@SCWR
Copy link
Author

SCWR commented Jan 18, 2019

First cmder is really easy to use, so I used it on vscode.
Remember that the version used for the first time is 1.3.5.
The version control tools used by my company project are git and svn. When I use it under git, everything works fine, but one day I developed a project under svn, and the vscode terminal crashed. I checked the lua script error.
Because lua is not a development language I am proficient in, so I try to google it. I found it

string.gsub(clink.prompt.value, "{svn}", color.."("..branch..")")

Because Chinese is encoded after %% of the situation, and then in the string replacement may be judged as an escape code resulting in an error.
Why is there no problem under git, I think that the people who use git are basically programmers, and because the existence of github and the recommended use of English, the project path is generally English.
The svn situation is more complicated. At the beginning, the person in charge started to build a Chinese directory, such as 代码管理, and then used English to build the project, so there is a Chinese path. ╮(╯▽╰)╭
So the way I solved it for the first time is the same as this one.

branch = string.gsub(branch, "%%", "%%%%")

The program did not report an error, but the output text is as follows.

snipaste_2019-01-18_09-33-09

I have a little obsessive-compulsive disorder, I don't think it is very good. I found that because Chinese is encoded, can I transcode it? So I google it again. Get this plan.
The result was successful like this.

snipaste_2019-01-18_09-38-16

After that, every time I upgrade the cmder, I need to change the change to the new version of the lua script compared to the previous lua script.
Until this upgrade, I found that the solution was consistent with my first solution. So I boldly fork it, modify and propose the merge application, so I don't need to manually modify the lua script for the next upgrade. As I said before, lua is not a development language that I am proficient in, so I hope you can check it out and make the correct changes.

I hope to help you a little.

Finally, cmder is really easy to use, ^_^

@daxgames
Copy link
Member

daxgames commented Mar 1, 2019

Can someone that uses SVN confirm this does not break anything?

@stale stale bot added the 👀 Awaiting Response Waiting to hear back from the issue reporter. label May 25, 2019
@stale stale bot closed this Jun 1, 2019
@DRSDavidSoft DRSDavidSoft self-requested a review December 3, 2022 21:26
@DRSDavidSoft DRSDavidSoft self-assigned this Dec 3, 2022
@DRSDavidSoft DRSDavidSoft added the 📌 Pinned Issue will not become stale label Dec 3, 2022
@DRSDavidSoft DRSDavidSoft reopened this Dec 3, 2022
@stale stale bot removed the 👀 Awaiting Response Waiting to hear back from the issue reporter. label Dec 3, 2022
@DRSDavidSoft DRSDavidSoft added the 👆 clink Upstream issue in clink. label Dec 29, 2022
@DRSDavidSoft DRSDavidSoft added this to the 1.4 milestone Dec 29, 2022
@chrisant996
Copy link
Contributor

Merging this would make the prompt show inaccurate path names, for example if a path name is literally "My%20Home" (as was recently mentioned in #2859) then it would be displayed as "My Home" which is inaccurate (typing cd "My Home" would fail because that's not the actual path name in the file system).

Svn should only convert Unicode URIs into URI-escaped strings (e.g. "https://some.where/over%20there"). It should not convert Unicode path names into URI-escaped strings. URIs and path names do not have the same escaping rules. If svn is performing that conversion automatically when writing output, then that seems like a bug or a misconfiguration.

If someone manually converted Unicode path names in the file system to use URI escaping rules so that the path names in the file system have "%XX" sequences in them, then Cmder prompt should not translate those -- that would be misleading. It would be reasonable for a user or a team to make a custom prompt filter that performs such translations, but it shouldn't be the default all users.

Also, the verbatim() function already has a specific different purpose. Even if URI decoding were to be applied for all users, it should be done in a separate function, not in the verbatim() function. And also, PR #2861 removes the verbatim() function and adds a gsub_plain() function instead, to simplify and clarify what the Cmder prompt string find/replace functions are trying to do.

@cmderdev cmderdev deleted a comment from stale bot Jul 12, 2023
@cmderdev cmderdev deleted a comment from stale bot Jul 12, 2023
@DRSDavidSoft
Copy link
Contributor

Closing this, as verbatim() was not the correct function to implement this, and it shouldn't be enabled by default anyway, and #2861 was merged, which this PR conflicts with that.

@chrisant996 Can you please write a short and working prompt filter that would call decodeURI() on a part or the whole of prompt? I believe it would serve as a nice example for the future Cmder users who might want to implement features like this for their prompt.

If it's too much trouble, I'd also appreciate a very short guide or writeup, or even pointing to the relevant section of the documentation for Clink.

Thanks!

@chrisant996
Copy link
Contributor

Cmder already includes the scripts from clink-completions under vendor\clink-completions, and the git_prompt.lua script demonstrates how to do post-processing to modify prompt text that's been generated by a different prompt filter.

Clink docs have quite a lot of content about writing prompt filters, and the section Customizing the Prompt is a good place to start.

I don't think decodeURI is a good example to create, as it's only applicable to maybe a handful of people who have done very unusual (and problematic!) manual encoding of paths in svn, seemingly to work around not knowing how to configure svn properly. The git_prompt.lua example is much better and much more widely applicable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👆 clink Upstream issue in clink. 📌 Pinned Issue will not become stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants