Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9122ef8
Implement WriteStringValueSegment defined in Issue 67337
ificator Apr 21, 2024
e044b13
Fix some review comments
ificator May 26, 2024
e7abe7f
merge upstream/main
ificator May 26, 2024
b8d578c
Handle split surrogate pair
ificator May 26, 2024
181cef2
Merge remote-tracking branch 'upstream/main' into user/ificator/write…
ificator Dec 6, 2024
65006ce
Commit old changes responding to comments
ificator Dec 6, 2024
1601af8
utf8 and utf16
PranavSenthilnathan Dec 11, 2024
d6b66be
fix build error
PranavSenthilnathan Dec 16, 2024
a46a1cc
Update src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf…
PranavSenthilnathan Dec 16, 2024
b5d0c17
Update src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf…
PranavSenthilnathan Dec 16, 2024
4a0d1c6
PR comments
PranavSenthilnathan Dec 16, 2024
09d321d
Merge branch 'main' of https://github.com/dotnet/runtime into user/if…
PranavSenthilnathan Dec 16, 2024
96ed922
add encoding flags
PranavSenthilnathan Dec 17, 2024
a078bfd
add test for switching encoding
PranavSenthilnathan Dec 17, 2024
93e6ee9
use CoreLib Rune for polyfill instead of having a separate copy
PranavSenthilnathan Dec 17, 2024
501813f
Merge branch 'main' of https://github.com/dotnet/runtime into user/if…
PranavSenthilnathan Dec 17, 2024
c3b1c3b
move warning disabling to top and fix up tests
PranavSenthilnathan Dec 18, 2024
c9c4884
add fuzzer
PranavSenthilnathan Dec 19, 2024
8482b1c
Fix some tests I missed
PranavSenthilnathan Dec 19, 2024
d50bbca
clean up and add another test to fuzzer
PranavSenthilnathan Dec 19, 2024
55827d9
comment typo
PranavSenthilnathan Dec 20, 2024
a5cd855
pr comments
PranavSenthilnathan Dec 20, 2024
c82b035
Merge branch 'main' of https://github.com/dotnet/runtime into user/if…
PranavSenthilnathan Dec 20, 2024
4f63907
Merge branch 'user/ificator/writestringvaluesegment' of https://githu…
PranavSenthilnathan Dec 20, 2024
b7fd4a5
throw when encodings are mixed
PranavSenthilnathan Dec 24, 2024
c0a700c
update fuzzer to assert that mixing encodings always throws
PranavSenthilnathan Dec 24, 2024
4d8a047
pr comments
PranavSenthilnathan Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libraries/System.Text.Json/ref/System.Text.Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ public void WriteStringValue(System.ReadOnlySpan<byte> utf8Value) { }
public void WriteStringValue(System.ReadOnlySpan<char> value) { }
public void WriteStringValue(string? value) { }
public void WriteStringValue(System.Text.Json.JsonEncodedText value) { }
public void WriteStringValueSegment(System.ReadOnlySpan<byte> utf8Value, bool isFinalSegment) { }
public void WriteStringValueSegment(ReadOnlySpan<char> value, bool isFinalSegment) { }
}
}
namespace System.Text.Json.Nodes
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Text.Json/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,8 @@
</data>
<data name="NullabilityInfoContext_NotSupported" xml:space="preserve">
<value>NullabilityInfoContext is not supported in the current application because 'System.Reflection.NullabilityInfoContext.IsSupported' is set to false. Set the MSBuild Property 'NullabilityInfoContextSupport' to true in order to enable it.</value>
</data>
<data name="CannotWriteWithinString" xml:space="preserve">
<value>The current JSON string must be finalized before a token of type '{0}' can be added.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ private static string GetResourceString(ExceptionResource resource, int currentD
case ExceptionResource.CannotWriteValueAfterPrimitiveOrClose:
message = SR.Format(SR.CannotWriteValueAfterPrimitiveOrClose, tokenType);
break;
case ExceptionResource.CannotWriteWithinString:
message = SR.Format(SR.CannotWriteWithinString, tokenType);
break;
default:
Debug.Fail($"The ExceptionResource enum value: {resource} is not part of the switch. Add the appropriate case and exception message.");
break;
Expand Down Expand Up @@ -758,6 +761,7 @@ internal enum ExceptionResource
ExpectedOneCompleteToken,
NotEnoughData,
InvalidLeadingZeroInNumber,
CannotWriteWithinString,
}

internal enum NumericType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ private void ValidateWritingProperty()
{
if (!_options.SkipValidation)
{
// Make sure a new property is not attempted within an unfinalized string.
ValidateNotWithinUnfinalizedString();

if (!_inObject || _tokenType == JsonTokenType.PropertyName)
{
Debug.Assert(_tokenType != JsonTokenType.StartObject);
Expand All @@ -49,6 +52,9 @@ private void ValidateWritingProperty(byte token)
{
if (!_options.SkipValidation)
{
// Make sure a new property is not attempted within an unfinalized string.
ValidateNotWithinUnfinalizedString();

if (!_inObject || _tokenType == JsonTokenType.PropertyName)
{
Debug.Assert(_tokenType != JsonTokenType.StartObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public void WriteCommentValue(ReadOnlySpan<char> value)

private void WriteCommentByOptions(ReadOnlySpan<char> value)
{
ValidateWritingComment();

if (_options.Indented)
{
WriteCommentIndented(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,29 @@ namespace System.Text.Json
{
public sealed partial class Utf8JsonWriter
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ValidateNotWithinUnfinalizedString()
{
if (_tokenType == StringSegmentSentinel)
{
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.CannotWriteWithinString, currentDepth: default, maxDepth: _options.MaxDepth, token: default, _tokenType);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ValidateWritingComment()
{
// Make sure a new comment is not attempted within an unfinalized string.
ValidateNotWithinUnfinalizedString();
}

private void ValidateWritingValue()
{
Debug.Assert(!_options.SkipValidation);

// Make sure a new value is not attempted within an unfinalized string.
ValidateNotWithinUnfinalizedString();

if (_inObject)
{
if (_tokenType != JsonTokenType.PropertyName)
Expand Down
Loading