tulir / gomuks

A Matrix client written in Go.
https://maunium.net/go/gomuks
GNU Affero General Public License v3.0
1.37k stars 123 forks source link

Command.RawArgs has surrounding whitespace trimmed #373

Open FiskFan1999 opened 2 years ago

FiskFan1999 commented 2 years ago

Hello tulir and gomuks contributors,

This PR trims the extreme left and right whitespace around command.RawArgs, which, among other things, is used as the path of the file in the /upload command. I found the following behavior when using gomuks in macos: in the terminal, you're allowed to drag and drop a file from the desktop or "finder", and terminal pastes the absolute path, followed by a space. This caused gomuks on the latest master branch to throw a file not found exception, while taking care to delete the extra space character succeeds of course (steps to reproduce: in any room, type /upload /correct/path/to/file followed by a space, . This should fail and throw a "file not found" error).

strings.TrimSpace only trims space on the extreme left and right. Since strings.Fields also trims this whitespace as well as whitespace between the words I think it is reasonable to trim whitespace for command.RawArgs. As far as I can tell, this doesn't break any other commands that RawArgs is used for.

Thank you, am looking forward to your input on this.

pataquets commented 2 years ago

@tulir: Anything else needed to merge this in?