51Degrees / common-cxx

A shared functionality library that is used by 51Degrees products
Other
0 stars 6 forks source link

yaml reader does not consider quoted strings #39

Open jwrosewell opened 6 months ago

jwrosewell commented 6 months ago

The yaml file reader does not remove quotes from strings. This results in invalid evidence being provided when used in tests and examples impacting the results.

The reader can also miss identify the end of a document and return fewer evidence pairs than expected. This also impacts the results of examples and tests that use the feature.

Jamesr51d commented 6 months ago

Background

51Degrees uses the YAMLDotNet YAML serializer when generating a test evidence file. Below are some transformations the serializer makes during serialization:

‘hello world“’hello world” (wraps in double quotes)

hello’ worldhello’ world (leaves as plain)

hello world’hello world’ (leaves as plain)

‘hello world“ ‘hello world” (wraps in double quotes)

“hello world”‘”hello world”’ (wraps in single quotes)

Notice the double quotes are used to wrap the string only when the single quote is the first non-whitespace character in the string. 51Degrees receives, in comparatively low volume, unique HTTP Headers that present in this format. The merge above deals with wrapping single quotes but, after further testing, the YAML Parser did not deal with the scenario where the string is wrapped in double quotes. This is due to the nature of Client Hint headers' format being wrapped in double quotes and those double quotes should not be stripped out.

Objective

When the YAML parser is processing evidence headers, it should account for the scenario where a useragent's first non -whitespace character is a single quote and has then been wrapped in double quotes by a YAML serializer. f.e “’hello world”

Tests

  1. Test that a useragent wrapped in double quotes has those double quotes properly stripped out.
  2. Test that client hint evidence is left untouched and treated as plain(double quotes not stripped).
  3. Test that single quote positions other than as the first non-whitespace character are not affected.

Documentation

  1. Document the feature as part of the spec
  2. Document the feature as part of the API readme
  3. Properly add comments in the implementation.
  4. Documentation added to the website.