Boeing / config-file-validator

Cross Platform tool to validate configuration files
https://boeing.github.io/config-file-validator/
Apache License 2.0
348 stars 71 forks source link

Paths not trimmed throws exception when path starts with space #158

Closed hype8912 closed 3 months ago

hype8912 commented 3 months ago

Below is the command line I used and accidentally left a space in the beginning when I was trying to call a file directly. You can duplicate it with any file type by leaving a space at the beginning of the quotes.

Environment:

validator -quiet " C:\Temp\dotnet_examples\DotNet Examples\BenchmarkRunner\TestObjects\HashFile_Small.xml"

Here's the output:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x28 pc=0xa075a5]

goroutine 1 [running]:
github.com/Boeing/config-file-validator/pkg/finder.FileSystemFinder.findOne.func1({0xc0000660c0, 0x57}, {0x0, 0x0}, {0x57?, 0x5c?})
        /github/workspace/pkg/finder/fsfinder.go:122 +0x45
path/filepath.WalkDir({0xc0000660c0, 0x57}, 0xc000087810)
        /usr/local/go/src/path/filepath/path.go:531 +0x9c
github.com/Boeing/config-file-validator/pkg/finder.FileSystemFinder.findOne({{0xc000020500, 0x1, 0x1}, {0xd19540, 0xb, 0xb}, 0xc00001b590, 0xc00001b5c0, 0x0}, {0xc0000660c0, ...})
        /github/workspace/pkg/finder/fsfinder.go:119 +0x198
github.com/Boeing/config-file-validator/pkg/finder.FileSystemFinder.Find({{0xc000020500, 0x1, 0x1}, {0xd19540, 0xb, 0xb}, 0xc00001b590, 0xc00001b5c0, 0x0})
        /github/workspace/pkg/finder/fsfinder.go:81 +0x18b
github.com/Boeing/config-file-validator/pkg/cli.CLI.Run({{0xb1db40?, 0xc000065ae0?}, {0xb1dba0?, 0xd9e580?}})
        /github/workspace/pkg/cli/cli.go:82 +0x56
main.mainInit()
        /github/workspace/cmd/validator/validator.go:225 +0x6e7
main.main()
        /github/workspace/cmd/validator/validator.go:234 +0x13

If you remove the space at the beginning of the quoted path it runs correctly. Not a major issue since there is a workaround.

mahadzaryab1 commented 3 months ago

@kehoecj i'd be happy to work on fixing this - are you still looking for someone to take this on?

kehoecj commented 3 months ago

@kehoecj i'd be happy to work on fixing this - are you still looking for someone to take this on?

@mahadzaryab1 yes, thank you!

mahadzaryab1 commented 3 months ago

I can't seem to reproduce the error on a Mac. I'm doing the following


./validator " test/fixtures/good.json"
2024/08/15 10:05:08 An error occurred during CLI execution: Unable to find files: stat  test/fixtures/good.json: no such file or directory

I am on a MacOS laptop so is this issue specific to Windows?

kehoecj commented 3 months ago

I can't seem to reproduce the error on a Mac. I'm doing the following

./validator " test/fixtures/good.json"
2024/08/15 10:05:08 An error occurred during CLI execution: Unable to find files: stat  test/fixtures/good.json: no such file or directory

I am on a MacOS laptop so is this issue specific to Windows?

Yeah, if you can't reproduce on a mac it sounds like it's windows-only

mahadzaryab1 commented 3 months ago

@kehoecj Do you have any suggestions on how I can go about testing the change?

kehoecj commented 3 months ago

@kehoecj Do you have any suggestions on how I can go about testing the change?

That's going to be tough - some options:

mahadzaryab1 commented 3 months ago

@kehoecj I've got a PR open to remove all the leading and trailing whitespaces in a path (https://github.com/Boeing/config-file-validator/pull/162)