lrstanley / girc

:bomb: girc is a flexible IRC library for Go :ok_hand:
https://pkg.go.dev/github.com/lrstanley/girc
MIT License
137 stars 13 forks source link

Special treatment of 'trailing' argument in commands is incorrect #35

Closed Bevinsky closed 5 years ago

Bevinsky commented 5 years ago

The IRC RFC says this about the format of commands:

<params>   ::= <SPACE> [ ':' <trailing> | <middle> <params> ]

<middle>   ::= <Any *non-empty* sequence of octets not including SPACE
               or NUL or CR or LF, the first of which may not be ':'>
<trailing> ::= <Any, possibly *empty*, sequence of octets not including
                 NUL or CR or LF>

and

  2)    After extracting the parameter list, all parameters are equal,
        whether matched by <middle> or <trailing>. <Trailing> is just
        a syntactic trick to allow SPACE within parameter.

In essence, there is no semantic difference between an argument parsed as a 'middle' or one as a 'trailing'. Trailing is simply a syntactic specification to allow the last argument in a command to contain spaces, if so desired.

However, girc doesn't follow this footnote and explicitly encodes 'trailing' as some special kind of command parameter. This is incorrect; if a command has a 'trailing' parameter, this is simply the last parameter of the command. There is no special meaning to it.

This makes the library cumbersome to use at best (since special care must be taken in regards to 'empty trailing', which should not be necessary at all), and broken at worst (since IRCds are within their rights to send commands for which you would 'expect' a trailing argument without one, such as PRIVMSG, or send commands with a trailing argument which you would not expect to have one).

This is IMHO a very huge flaw in the library and should be fixed before it goes 1.0.

lrstanley commented 5 years ago

Yep, I'm aware. I've had plans to change this for some time now, just haven't had the chance. See:

https://github.com/lrstanley/girc/pull/15#issuecomment-413845482

lrstanley commented 5 years ago

Had some time last night and figured I'd try and knock this out. Almost complete, should be able to finish later today.

lrstanley commented 5 years ago

Take a look at https://github.com/lrstanley/girc/pull/36 -- I'm sure there are likely to be bugs lurking with weird off-by-one issues, due to how things had to be handled the old way. LMK.