Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@MPagel
Copy link
Contributor

@MPagel MPagel commented Nov 14, 2018

Should differentiate between REG_SZ (or MULTI) and REG_EXPAND_SZ

replaced ::s with REM to avoid "the system cannot find the drive specified" errors
removed any pauses and the not-always-supported ECHO | SET /P syntax
replaces SET with CALL SET to allow variables to resolve before setting (using !s would be another option potentially)
Removes temp batch file after running

Intended to address Issue #1664

replaced `::`s with `REM` to avoid "the system cannot find the drive specified" errors
removed any pauses and the not-always-supported `ECHO | SET /P` syntax
replaces `SET` with `CALL SET` to allow variables to resolve before setting (using !s would be another option potentially)
Removes temp batch file after running
Should differentiate between REG_SZ (or MULTI) and REG_EXPAND_SZ
@ferventcoder ferventcoder changed the title fix issues with % symbols in environment variable expansion (GH-1664) fix issues with % symbols in environment variable expansion May 20, 2019
Copy link
Member

@ferventcoder ferventcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, looks great so far!

I've noted a few things to fix up here. In addition, the commit also needs updated to follow the format we request in CONTRIBUTING.md (top level of repo).

@ferventcoder ferventcoder added the 0 - Waiting on User Insufficient information for issue or PR, issue may be closed if no response from user. label May 20, 2019
Removed personal debug lines and in-line comments in addition to changing `echo.` and `echo ` to `echo/

Echo changes as per https://groups.google.com/forum/?hl=en#!msg/alt.msdos.batch.nt/VhNXmRQEcVk/J3-C8ViGOD0J

Comment lines removed include
[code]
REM Just echo. Don't bother prompting.
REM (WAS) set /p dummy="[text below] Press a key to continue..."

REM  (DEBUG) echo ParentKey: %~1     VarName: %~2        OutVarName: %~3 1>&2
REM  (DEBUG) type "%temp%\_envset.tmp" 1>&2
REM      (DEBUG) echo MatchFound: %~3 eq %%B 1>&2

REM (WAS) set /p dummy="Finished. Press a key to close window."
[/code]
Copy link
Contributor Author

@MPagel MPagel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(let me know if not in line with contributing.md)

Copy link
Contributor Author

@MPagel MPagel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to go.

Copy link
Contributor Author

@MPagel MPagel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@MPagel MPagel requested a review from ferventcoder December 20, 2019 18:49
@CLAassistant
Copy link

CLAassistant commented Jun 8, 2020

CLA assistant check
All committers have signed the CLA.

@ferventcoder
Copy link
Member

We'll be gearing back up to look at this soon!

@gep13
Copy link
Member

gep13 commented Apr 16, 2021

@MPagel I am starting to go through the backlog of PR's into this repository, apologies for not getting back to you sooner about this. Are you in a position to sign the CLA for the project? You can find it linked in the previous comment. Thanks

@gep13 gep13 changed the title (GH-1664) fix issues with % symbols in environment variable expansion (#1664) fix issues with % symbols in environment variable expansion Oct 14, 2021
@MPagel
Copy link
Contributor Author

MPagel commented Apr 12, 2022

@gep13 didn't see your comment until now. All I see when I go to the cla page is "Please agree to the CLA for multiple repositories or organizations

Version: "

and then a text box which doesn't accept input. no confirm/deny button is present.

@TheCakeIsNaOH
Copy link
Member

@MPagel This is what I see when going to https://cla-assistant.io/chocolatey/choco?pullRequest=1678
image

And at the bottom of the page:

image

If you are not seeing that, perhaps try a different browser, and disable any adblockers/anti trackers for the site

@MPagel
Copy link
Contributor Author

MPagel commented Apr 13, 2022

No external ad blockers installed.
Pictured left: firefox
middle: edge
right: chrom
Firefox_Edge_Chrome
e

@MPagel
Copy link
Contributor Author

MPagel commented Apr 13, 2022

finally updated and loaded on firefox. I believe I have signed it now.

it doesn't say here that I have signed, but CLA assistant thanked me for signing and redirected me back here.

@gep13
Copy link
Member

gep13 commented Apr 13, 2022

@MPagel said...
it doesn't say here that I have signed, but CLA assistant thanked me for signing and redirected me back here.

I can confirm that this has now been signed, thank you!

@github-actions github-actions bot added the Pending Closure This issue has been marked as having no response or is stale and will soon be closed. label Jun 11, 2023
@github-actions
Copy link

Dear contributor,

As this PR seems to have been inactive for 30 days after changes / additional information
was requested, it has been automatically closed.
If you feel the changes are still valid, please re-open the PR once all changes or additional information
that was requested has been added.
Thank you for your contribution.

@github-actions github-actions bot added the No Response / Stale Used on issues when additional information is requested, and no response has been given. label Jun 25, 2023
@github-actions github-actions bot closed this Jun 25, 2023
@pauby pauby reopened this Jun 25, 2023
@pauby pauby removed 0 - Waiting on User Insufficient information for issue or PR, issue may be closed if no response from user. No Response / Stale Used on issues when additional information is requested, and no response has been given. Pending Closure This issue has been marked as having no response or is stale and will soon be closed. labels Jun 25, 2023
@AdmiringWorm
Copy link
Member

@MPagel I appologies for everything taken so long, we are currently looking at attempting to pull this PR into the next release of Chocolatey CLI, and as part of that I have taken this PR for a test run.

Unfortunately, from what I can tell, I am not able to see it fixing the issue that was reported (with the steps) in issue #1664. Can you confirm what it is that you expect to fix with this PR?

Additionally, due to my limited understanding of bat/cmd, what is the reason for the use of for the echo/call set item?

@MPagel
Copy link
Contributor Author

MPagel commented Jun 4, 2025

Disclaimer: As it has been several years since I made the contribution, I'm only 99% sure of my comments to follow

The echo/set construction was present in the pre-modified code (lines 61 and 62 in the PR do what line 46 did in the original). Basically, my understanding is it is appending a SET command into an _env.cmd file in the temp directory. The SET instruction is not immediately executed, rather this temp file is later executed during the course of the script (line 57 original).

The modification in the PR IIRC should allow literal % values to be retained in the PATH environment variable, while allowing the expansion of other variables between two %s, as DOS itself allows.

I just ran the "bobo" script in a windows 11 cmd window, and it performed exactly as indicated in the REM statements. Is this what you were not able to replicate?

Image

@gep13
Copy link
Member

gep13 commented Jun 6, 2025

@MPagel thank you for getting back to us about this, we really appreciate it! We understand that it has been quite a while to get to this PR. I like to say that around here, sometimes the wheels turn slowly, but they do indeed turn! 😄

I am just working with @AdmiringWorm on this, and so far, we have not been able to validate that the changes you have made to the refreshenv.cmd in this PR. Let me explain what we have done...

Like you, we have taken the bobo script, and ran it in a fresh Windows Command Prompt, and we get the same output as you. So that part is working as described. However, we have then taken the following steps...

  1. Opened a Windows 10 VM
  2. Taken a backup of the refreshenv.cmd in the C:\ProgramData\chocolatey\bin folder
  3. Replaced the contents of the refreshenv.cmd with the contents of the file in this PR
  4. Opened a fresh Windows Command Prompt
  5. Ran setx test test%20value
  6. We then opened a new Windows Command Prompt
  7. We then ran set and verified that the value of variable test is test%20value
  8. We then ran refreshenv
  9. We then ran set and verified that the value of variable test is test0value

i.e. with your changes to the Refreshenv.cmd in place, the value for the in process environment variable is no longer correct.

Can you verify whether these steps actually work for you? Or are you doing something else?

Looking at the _env.cmd file that is generated, it contains the following:

call set "test=test%%20value"

Is that what you are expecting it to contain?

Thanks again for your help with this!

@gep13
Copy link
Member

gep13 commented Jun 6, 2025

If we change the contents of the _env.cmd file to use:

set "test=test%%20value"

rather than:

call set "test=test%%20value"

We can see that the contents of the test variable are now "correct", however, we an unsure about whether the call set is needed and would have other knock on consequences that are unrelated to the problem that is being faced here.

@gep13
Copy link
Member

gep13 commented Jun 6, 2025

Digging into this a little bit further, we just wanted to clarify that this only seems to be a problem on Windows Command Prompt, the same problem does not appear to happen when using Windows PowerShell.

@gep13
Copy link
Member

gep13 commented Jun 6, 2025

Looking at the refreshenv.cmd would it make sense to change this:

            IF /I "%%~A"=="REG_EXPAND_SZ" (
                echo/call set "%~3=%%B"
            ) ELSE (
                set "tempvar=%%B"
                echo/call set "%~3=!tempvar:%%=%%%%!"
            )

to this:

            IF /I "%%~A"=="REG_EXPAND_SZ" (
                echo/call set "%~3=%%B"
            ) ELSE (
                set "tempvar=%%B"
                echo/set "%~3=!tempvar:%%=%%%%!"
            )

NOTE: The removal of call in the ELSE statement.

@MPagel
Copy link
Contributor Author

MPagel commented Jun 9, 2025

thank you for the detailed breakdown of what you tried. IIRC the call set was done for variable scope reasons. But if it doesn't work with the call and does work without it, then I guess I had the scoping requirements backwards or otherwise wrong.

my use case was with the PATH environmental variable, so I don't know if that makes any difference from what you were trying. I also may not have tried with setx across different sessions, but MAY have just been trying to refresh the value within a single session.

@AdmiringWorm
Copy link
Member

As there was a need to rebase and update the bat script to be compatible with the latest version of the RefreshEnv.cmd file, and since we needed to make some additional changes to it related to a different issue, we decided to include your changes after modifying it in PR #3688.

We have left you as the original committer for the commits that were added to give proper attribution, but as it will be merged as a different PR I'll be closing this PR now.

We do appreciate the work you have done, and the patience you have shown to get this added to Chocolatey CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Execution of the refreshenv command incorrectly removes % (percent) characters from environment variable values

7 participants