Skip to content

JS tests that are sensitive to default toString() methods #2517

@hmakholm

Description

@hmakholm

With the CodeQL CLI, the handling of toString() methods in QL changes. The default compilation mode in Odasa was that entity classes that don't declare a toString() inherit the default implicit none() behavior. In contrast, the new CodeQL CLI compiles with --default-to-string by default, which corresponds to a default behavior that could be expressed as

String toString() { result = "" }

These differences also apply between odasa qltest and (the yet-to-be-released) codeql test run. There are a few existing tests where this difference matters -- namely where a missing toString() definition in the library and/or test code previously made some row disappear from the output due to not having any string representation. Thus the existing .expected file will not contain these rows, but codeql test run will produce them, making the test fail.

It has been decided that this ought to be fixed by making sure that tests always declare all relevant toString() methods, such that their output is independent of the compilation mode.

For JavaScript, the tests affected are:

  • ql/javascript/ql/test/library-tests/XML/XMLParent_getTextValue.ql

Please fix these -- ideally by making sure the relevant entity classes have toString() methods, but in a pinch just by injecting some and a.toString() != "" conditions in the select clauses.

To test that your fix works:

  1. check out branch pr/test-extract of git.semmle.com/henning/code
    • if this branch doesn't exist, it might be that #35764 has been merged, in which case you can just use Semmle/code/master.
  2. build target/intree/codeql.
  3. try running your test both with codeql test run path/to/test.ql and with codeql test run --no-default-to-string path/to/test.ql.

(Once all the tests have been updated, we will modify the behavior of odasa qltest appropriately, so a new divergence between the tools won't arise).

Metadata

Metadata

Assignees

No one assigned

    Labels

    JSbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions