TestFilterBuilder builds invalid XML
See original GitHub issue(Updated)
This implementation mishandles surrogate pairs. Control characters other than tab, carriage return and line feed cannot be represented in XML and should throw, IIRC. (See https://github.com/nunit/nunit3-vs-adapter/issues/484.)
GetFilter()
should be using XmlWriter.Create
to a StringWriter
. This will not only get us out of the responsibility of implementing the XML spec, it will probably also result in some significant performance gains. (Judging by the chained string.Replace
calls.)
(Test names containing control characters cannot be represented in XML without first encoding using base64 or something custom. This will need to be dealt separately with in the framework.)
@nunit/engine-team Does this seem right to you? Can we let @MatthewBeardmore get started on this if he is interested?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:13 (8 by maintainers)
There’s a lot of moving parts in this issue, but I think Joseph has summed it up quite well here: https://github.com/nunit/nunit/issues/3063#issuecomment-432788447
Currently, for the example shown at https://github.com/nunit/nunit3-vs-adapter/issues/484, the framework by default gives that a test name which can’t legally be represented by XML. This seems to cause unpredictability when the framework/engine/runners all rely on xml to encode their communications.
IMO, the framework should be changed to not create xml-invalid names by default, and prevent users overriding this with SetName. For the engine’s part, it should only:
If the framework doesn’t create test names as per item 1, then I can’t think of any valid need for item 2 - the engine just needs to handle this elegantly.
@jnm2 I may be missing something but here’s what I was thinking…
There is no valid method name containing control characters. Therefore, no default test name can contain control characters and such a test name can only be created by the user using SetName. However, such a test name serves no useful purpose if we can’t use it for filtering so why not just eliminate such names by disallowing control characters in SetName?
This might be “breaking” in the sense that you would get an error message rather than just fail to select the test, but so what?