Implement a parser for ircv3 and add unit tests to it.

Review Request #1874 — Created Oct. 1, 2022 and submitted

Information

pidgin/pidgin
default

Reviewers

This change got pretty big so I didn't implement unescapping tags yet. I did
however put the unit tests in for escaped tags, but they are currently #if 0'd
out.

The unit tests are based on the msg-split test cases from https://github.com/ircdocs/parser-tests/blob/master/tests/msg-split.yaml

Ran the unit tests.

Summary ID
Implement a parser for ircv3 and add unit tests to it.
This change got pretty big so I didn't implement unescapping tags yet. I did however put the unit tests in for escaped tags, but they are currently #if 0'd out.
53c1b425e7d8acebe2e79bd6586cfb39fb09eb9f
Description From Last Updated

Wrong guard macro name.

QuLogicQuLogic

I might just be missing something about the contract around the tags_string but shouldn't this be something like if(tags_string == …

hub@cerras.devhub@cerras.dev

If it's never NULL, then you don't need the tag_string != NULL.

QuLogicQuLogic

local_error was already checked and returned, so this can't happen.

QuLogicQuLogic

handler

QuLogicQuLogic

I'm surprised this is not triggering anything in valgrind, as g_strfreev frees both params and the strings in it. But …

QuLogicQuLogic

Inconsistent indent.

QuLogicQuLogic

Walk

QuLogicQuLogic

Remove?

QuLogicQuLogic

The spacing around the braces on .params lines is a bit inconsistent.

QuLogicQuLogic

Not a big deal, but these are swapped from the order in the test data.

QuLogicQuLogic

Similar to the other control character test, this string is probably also wrong, but the compiler isn't warning because \x035 …

QuLogicQuLogic

Ditto.

QuLogicQuLogic

This is warning about an invalid hex escape sequence with \x0305, as YAML escapes are limited to 2 digits, but …

QuLogicQuLogic

Same here.

QuLogicQuLogic

It looks like you're missing one test above this one.

QuLogicQuLogic

Missing trailing comma also.

QuLogicQuLogic

Missing trailing comma.

QuLogicQuLogic
grim
hub@cerras.dev
  1. 
      
  2. libpurple/protocols/ircv3/purpleircv3parser.c (Diff revision 1)
     
     
     
     
     
    Show all issues

    I might just be missing something about the contract around the tags_string but shouldn't this be something like if(tags_string == NULL || *tags_string == '\0')

    1. tags_string will never be NULL because g_match_info_fetch_named always returns a string and never returns NULL.

  3. 
      
grim
QuLogic
  1. 
      
  2. Show all issues

    Wrong guard macro name.

  3. libpurple/protocols/ircv3/purpleircv3parser.c (Diff revision 1)
     
     
     
     
     
    Show all issues

    If it's never NULL, then you don't need the tag_string != NULL.

  4. libpurple/protocols/ircv3/purpleircv3parser.c (Diff revision 1)
     
     
     
     
    Show all issues

    local_error was already checked and returned, so this can't happen.

  5. Show all issues

    handler

  6. Show all issues

    I'm surprised this is not triggering anything in valgrind, as g_strfreev frees both params and the strings in it.

    But those strings were extracted in purple_ircv3_parser_parse_tags from middle with duplication, or is exactly trailing, which were both freed above.

    So this should have been a double-free.

    1. That should say 'from middle without duplication'.

    2. g_strv_builder_add dupes the value.

      void                                                                            
      g_strv_builder_add (GStrvBuilder *builder,                                      
                          const char   *value)                                        
      {                                                                               
        g_ptr_array_add (&builder->array, g_strdup (value));                          
      }
      
    3. Ah okay, but didn't you skip using g_strsplit in order to avoid the duplication? But if the duping is fine, then this can be dropped.

    4. I did, but we'd have to resize the GStrv or something because we'd split middle, and then append trailing as another item and I don't think there are any helpers for that, so GStrvBuilder actually solves all of that.

  7. Show all issues

    Inconsistent indent.

  8. Show all issues

    Walk

  9. Show all issues

    Remove?

  10. Show all issues

    The spacing around the braces on .params lines is a bit inconsistent.

  11. libpurple/protocols/ircv3/tests/test_ircv3_parser.c (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    Not a big deal, but these are swapped from the order in the test data.

    1. Their comment was with and without, but the first one has an input of ":src AWAY" which doesn't have any parameters after the command of AWAY. So, if there comment was more like without and with tests or if the input strings were swapped, then they'd be consistent.

  12. Show all issues

    This is warning about an invalid hex escape sequence with \x0305, as YAML escapes are limited to 2 digits, but C ones aren't.

    I think the only way to write it is to split the string, "coolguy!~ag@n\x02et\x03" "05w\x0fork.admin"

    1. Oh, e is also a valid hex character, so there should be a split between the \x02 and the e. Same with msg below.

  13. Show all issues

    Same here.

  14. Show all issues

    Missing trailing comma.

  15. 
      
QuLogic
  1. 
      
  2. Show all issues

    Similar to the other control character test, this string is probably also wrong, but the compiler isn't warning because \x035 is okay. It would also need the splitting to be right.

  3. Show all issues

    Ditto.

  4. Show all issues

    It looks like you're missing one test above this one.

  5. Show all issues

    Missing trailing comma also.

  6. 
      
grim
QuLogic
  1. Ship It!
  2. Checked all the tests and they match the original test data.

  3. 
      
grim
Review request changed
Status:
Completed