Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Cookie Crumble to ensure that snapshot files end with a newline #7378

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions src/CookieCrumble/src/CookieCrumble/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public async ValueTask MatchAsync(CancellationToken cancellationToken = default)
{
var writer = new ArrayBufferWriter<byte>();
WriteSegments(writer);
EnsureEndOfBufferNewline(writer);

var snapshotFile = Combine(CreateSnapshotDirectoryName(), CreateSnapshotFileName());

Expand Down Expand Up @@ -257,6 +258,7 @@ public void Match()
{
var writer = new ArrayBufferWriter<byte>();
WriteSegments(writer);
EnsureEndOfBufferNewline(writer);

var snapshotFile = Combine(CreateSnapshotDirectoryName(), CreateSnapshotFileName());

Expand Down Expand Up @@ -557,6 +559,17 @@ private string CreateSnapshotDirectoryName(bool mismatch = false)
: Combine(directoryName, "__snapshots__");
}

/// <summary>
/// Ensure that the specified writer's underlying buffer ends with a newline.
/// </summary>
private static void EnsureEndOfBufferNewline(ArrayBufferWriter<byte> writer)
{
if (writer.WrittenSpan.Length > 0 && writer.WrittenSpan[^1] != (byte)'\n')
{
writer.Append("\n");
}
}

private static void EnsureDirectoryExists(string file)
{
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"Foo": "Bar"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"Foo": "Bar"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"Foo": "Bar"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"Foo": "Bar"
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123
123
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
scalar _Any

"Scalar representing a set of fields."
scalar _FieldSet
scalar _FieldSet
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ directive @link("Gets imported specification url." url: String! "Gets optional l
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ directive @override(from: String!) on FIELD_DEFINITION
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ directive @override(from: String! label: String) on FIELD_DEFINITION
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ directive @policy("Retrieves list of a list of authorization policies to evaluat
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ directive @policy("Retrieves list of a list of authorization policies to evaluat
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ directive @policy("Retrieves list of a list of authorization policies to evaluat
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ directive @provides(fields: FieldSet!) on FIELD_DEFINITION
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ directive @provides(fields: FieldSet!) on FIELD_DEFINITION
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ directive @requires(fields: FieldSet!) on FIELD_DEFINITION
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ directive @requires(fields: FieldSet!) on FIELD_DEFINITION
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ directive @requiresScopes("Retrieves list of a list of required JWT scopes." sco
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ directive @requiresScopes("Retrieves list of a list of required JWT scopes." sco
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ directive @requiresScopes("Retrieves list of a list of required JWT scopes." sco
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
scalar _Any
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"data": {
"bar": "bar"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
],
"data": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
],
"data": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
],
"data": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
],
"data": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
},
"Errors": null,
"Extensions": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
}
],
"Extensions": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
}
],
"Extensions": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
},
"Errors": null,
"Extensions": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
},
"Errors": null,
"Extensions": null
}
}
Loading
Loading