Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Ignore empty header values #837

Merged
merged 1 commit into from
May 17, 2017
Merged

Conversation

JunTaoLuo
Copy link
Contributor

Addresses #722. Only retain non-empty header values from GetCommaSeparatedValues.

@@ -26,7 +26,7 @@ private static IEnumerable<string> GetHeaderSplitImplementation(StringValues val
{
foreach (var segment in new HeaderSegmentCollection(values))
{
if (segment.Data.HasValue)
if (segment.Data.HasValue && !string.IsNullOrWhiteSpace(segment.Data.Value))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better implemented in StringSegment in M.E.Primitives.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a separate bug to replace all IsNullOrWhiteSpace calls with IsNullOrEmpty. IsNullOrWhiteSpace checks for a bunch of unicode characters we don't want to check.

Copy link
Member

@Tratcher Tratcher May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, I'm working on adding a bunch of methods to StringSegment: dotnet/extensions#213, you may want to hold off on this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commited.


Assert.Equal(segments, result);
Assert.Equal(expectedResult, result);
Copy link
Contributor Author

@JunTaoLuo JunTaoLuo May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we wanted to test keeping empty values before @Tratcher?

@@ -26,7 +26,7 @@ private static IEnumerable<string> GetHeaderSplitImplementation(StringValues val
{
foreach (var segment in new HeaderSegmentCollection(values))
{
if (segment.Data.HasValue)
if (segment.Data.HasValue && !string.IsNullOrWhiteSpace(segment.Data.Value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a separate bug to replace all IsNullOrWhiteSpace calls with IsNullOrEmpty. IsNullOrWhiteSpace checks for a bunch of unicode characters we don't want to check.

@@ -26,7 +26,7 @@ private static IEnumerable<string> GetHeaderSplitImplementation(StringValues val
{
foreach (var segment in new HeaderSegmentCollection(values))
{
if (segment.Data.HasValue)
if (segment.Data.HasValue && !string.IsNullOrWhiteSpace(segment.Data.Value))
Copy link
Member

@Tratcher Tratcher May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, I'm working on adding a bunch of methods to StringSegment: dotnet/extensions#213, you may want to hold off on this change.

@JunTaoLuo
Copy link
Contributor Author

🆙📅

@@ -48,8 +51,9 @@ public void EmptyHeaderSegmentsAreParsable(IEnumerable<string> segments)
});

var result = headers.GetCommaSeparatedValues("Header1");
var expectedResult = segments.Where(s => !string.IsNullOrWhiteSpace(s));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsNullOrEmpty

@@ -26,7 +26,7 @@ private static IEnumerable<string> GetHeaderSplitImplementation(StringValues val
{
foreach (var segment in new HeaderSegmentCollection(values))
{
if (segment.Data.HasValue)
if (segment.Data.HasValue && !StringSegment.IsNullOrEmpty(segment.Data))
{
yield return DeQuote(segment.Data.Value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about empty quoted strings?

@JunTaoLuo JunTaoLuo force-pushed the johluo/ignore-empty-header-values branch from b4b5e6f to 2a6d771 Compare May 17, 2017 18:54
@JunTaoLuo
Copy link
Contributor Author

🆙📅

@JunTaoLuo JunTaoLuo force-pushed the johluo/ignore-empty-header-values branch from 2a6d771 to 07470d4 Compare May 17, 2017 19:46
@JunTaoLuo JunTaoLuo merged commit 07470d4 into dev May 17, 2017
@JunTaoLuo JunTaoLuo deleted the johluo/ignore-empty-header-values branch May 17, 2017 19:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants