Skip to content

[Bug]: Elements are skipped when a ReqIF document has no whitespace between elements #94

Closed

Description

@samatstariongroup

What type of issue is this?

  • Bug report
  • Feature request

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of the reqifsharp
  • I have searched open and closed issues to ensure it has not already been reported

Description

When a ReqIF document has no whitespace between its elements (minified XML, as some tools write it), the deserializer silently skips elements. There is no error and no log message; the values are simply missing from the object graph.

Seen in ReqIFHeader: with the header written on one line, CREATION-TIME and REQ-IF-TOOL-ID come back empty, while COMMENT and REPOSITORY-ID are read.

Cause

ReqIFHeader.ReadXml (and ReadXmlAsync) loops with while (reader.Read()) and reads each child with ReadElementContentAsString(). ReadElementContentAsString() already moves the reader past the end tag, onto the next node. In an indented document that node is whitespace, so the following Read() lands on the next element. Without whitespace the reader is already on the next element, and Read() moves past it: every other element is lost.

Scope

The same while (reader.Read()) loop is used in about 26 files (header, content, spec types, attribute definitions, attribute values, datatypes, hierarchies, tool extensions, alternative IDs). Which of them read their children in a way that skips the next sibling still has to be confirmed; a test as below will show it.

Proposal

  • Rewrite the affected loops so that an element read with ReadElementContentAs*, ReadInnerXml, ReadOuterXml or Skip does not get an extra Read(), in the sync and async paths.

Acceptance criteria

  • A copy of each test document with the whitespace between ReqIF elements removed (whitespace inside XHTML content kept) deserializes to the same object graph as the original, sync and async, .reqif and .reqifz.

Steps to Reproduce

  1. Take a test document such as ReqIFSharp.Tests/TestData/Datatype-Demo.reqif.
  2. Make a copy with the whitespace-only text nodes between ReqIF elements removed, e.g. XDocument.Parse(text).ToString(SaveOptions.DisableFormatting).
  3. Deserialize both and compare the header: in the copy CreationTime is 0001-01-01T00:00:00 instead of 2017-03-13T10:15:09.017+01:00, and ReqIFToolId is empty.

System Configuration

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions