Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • possible bug in Stata's -classutil- command

    Dear All

    Stata's classutil command is a utility for working with classes and objects.

    Specifically classutil des .someObject lists the properties defined for .someObject.

    It turns out that it does this in an unsafe manner, meaning that if a dollar sign occurs in the value of the property, it is not displayed verbatim, but rather interpreted as a beginning of a macro.

    Consider the following minimal example.

    First define a class file foobar.class and save it somewhere along your Stata's search path (for example, in the current directory):

    Code:
    // 2026 Sergiy Radyakin
    
    class foobar {
        string storage
    }    
    
    program define .new
      args d
      display _n as text `"`macval(d)'"'
      .storage = "`macval(d)'"
    end
    
    // END OF FILE
    Second, execute the following code:
    Code:
    clear all
    
    .g=.foobar.new "Te\$st"
    display `"`macval(.g.storage)'"'
    classutil des .g
    
    // END OF FILE
    The output looks like this:
    Click image for larger version

Name:	output.png
Views:	1
Size:	6.5 KB
ID:	1785398


    I don't see any real-world scenario where such output of classutil des would be useful and consider it a bug.

    The behavior I expect here is exhibited, for example, in the following:

    Code:
    clear all
    
    gen x=1
    label variable x "Te\$st"
    
    describe
    which does not attempt to evaluate special characters in the variable label (displays the label of the variable x with a proper dollar sign and subsequent text intact):

    Click image for larger version

Name:	output2.png
Views:	1
Size:	8.6 KB
ID:	1785399


    Hope this can be agreed as a bug and fixed (if not already).

    Thank you and have a good weekend!
    Sergiy

    StataNow/MP 19.5 for Windows (64-bit x86-64) | Revision 14 Jan 2026 | Windows
Working...
X