Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-153

Invalid code generated for string constants containing single quotes (')

    XMLWordPrintableJSON

Details

    • Patch Available

    Description

      If I declare a constant in a Thrift iDL like this:

      const string HAMMER_TIME = "Can't touch this";

      The generated Python sources generate a constant like this:

      HAMMER_TIME = 'Can't touch this';

      This doesn't work because the apostrophe terminates the string constant.

      Since Python supports string constants using either ' or ", an easy fix is just to use " around Python constants instead:

      Index: compiler/cpp/src/generate/t_py_generator.cc
      ===================================================================
      — compiler/cpp/src/generate/t_py_generator.cc (revision 701711)
      +++ compiler/cpp/src/generate/t_py_generator.cc (working copy)
      @@ -363,7 +363,7 @@
      t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
      switch (tbase) {
      case t_base_type::TYPE_STRING:

      • out << "'" << value->get_string() << "'";
        + out << '"' << value->get_string() << '"';
        break;
        case t_base_type::TYPE_BOOL:
        out << (value->get_integer() > 0 ? "True" : "False");

      Attachments

        Activity

          People

            shigin Alexander Shigin
            engberg Dave Engberg
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: