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)
     
     
     
     
     

    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. Wrong guard macro name.

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

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

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

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

  5. 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.

  6. Inconsistent indent.

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

  8. libpurple/protocols/ircv3/tests/test_ircv3_parser.c (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    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.

  9. 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.

  10. Missing trailing comma.

  11. 
      
QuLogic
  1. 
      
  2. 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. It looks like you're missing one test above this one.

  4. Missing trailing comma also.

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

  3. 
      
grim
Review request changed

Status: Closed (submitted)

Loading...