auto-commit-msg icon indicating copy to clipboard operation
auto-commit-msg copied to clipboard

Special characters in filenames are not properly encoded

Open Wikiwix opened this issue 1 year ago • 10 comments
trafficstars

If filenames contain non-ASCII characters this can lead to unexpected commit message suggestions. See for example this screenshot:

image

Wikiwix avatar Aug 18 '24 19:08 Wikiwix

hmm thanks. I was able to reproduce

but when I added unit tests, they pass.

e.g.

    describe("handle special characters in filenames", function () {
      it("should correctly parse a filename with special characters", function () {
        const expected: FileChange = {
          x: "A",
          y: " ",
          from: "abcëxyz.md",
          to: "",
        };

        assert.deepStrictEqual(parseDiffIndex("A\tabcëxyz.md"), expected);
      });
    });

MichaelCurrin avatar Aug 19 '24 13:08 MichaelCurrin

The problem is the git commands. I'll keep looking at this

$ npm run sb
$ cd sandbox
$ git add sp*
$ git ls
README.md
bazz.js
buzz.js
fizz.js
foo.js
"sp\303\253cial ch\303\242racters.md"

MichaelCurrin avatar Aug 19 '24 14:08 MichaelCurrin

Can you do this in your repo or globally across repos with --global?

git config core.quotePath false

Then try again and let me know if that works?

I started implementing a fix in the code but it touched a couple of files and then at some point the sandbox won't start beacuse of some error in vs code so I am stuck for now

MichaelCurrin avatar Aug 19 '24 16:08 MichaelCurrin

@MichaelCurrin With core.quotePath false it behaves as expected. If you call git within your code, you might simply want to add the matching config parameter using -c like in the following example:

git -c 'core.quotePath=false' ls-files

Wikiwix avatar Aug 19 '24 17:08 Wikiwix

from my quick testing it looks like that works.

image

MichaelCurrin avatar Aug 20 '24 12:08 MichaelCurrin

I've pushed the change on master if you want to build and install locally

git clone ... make all make e

I am not going to publish the change yet as a new version of the extension

MichaelCurrin avatar Aug 20 '24 12:08 MichaelCurrin

Hi, I've published a new version

MichaelCurrin avatar Nov 03 '24 18:11 MichaelCurrin

Nice, but for me the new version throws this error (on Windows)

2024-11-03 19:51:18.261 [error] Error: Command failed: git -c 'core.quotePath=false' diff-index --name-status --find-renames --find-copies --no-color --cached HEAD
error: invalid key: 'core.quotePath
fatal: unable to parse command-line config

	at genericNodeError (node:internal/errors:984:15)
	at wrappedFn (node:internal/errors:538:14)
	at ChildProcess.exithandler (node:child_process:423:12)
	at ChildProcess.emit (node:events:519:28)
	at maybeClose (node:internal/child_process:1105:16)
	at ChildProcess._handle.onexit (node:internal/child_process:305:5) commitMsg.autofill {"value":"MichaelCurrin.auto-commit-msg","_lower":"michaelcurrin.auto-commit-msg"}

Running the command from the error message works as expected in Powershell…

Wikiwix avatar Nov 03 '24 18:11 Wikiwix

In CMD I can recreate the error:

C:\Users\phili\dev\philips-wiki>git -c 'core.quotePath=false' diff-index --name-status --find-renames --find-copies --no-color --cached HEAD
error: invalid key: 'core.quotePath
fatal: unable to parse command-line config

Using double quotes or no quotes at all works though

EDIT: Single Quotes in CMD are just regular characters, so it is expected to not work in cmd

Wikiwix avatar Nov 03 '24 18:11 Wikiwix

@MichaelCurrin I prepared #114 with a fix

And by now I am sorry that I did not build the earlier version myself and test it. Then the (on Windows) broken release could have been prevented :/

Wikiwix avatar Nov 03 '24 20:11 Wikiwix