Cysharp / Cysharp/WebSerializer

Query string starts with `&` when the first property is null

Open Beginner friendly
#23 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
79
Forks
6
PR merge metrics
No merged PRs in 30d

Description

It seems that if the first property is null, the serialized output starts with &.

#!/usr/bin/env dotnet run
#:package WebSerializer@1.3.0

using System.Runtime.Serialization;
using Cysharp.Web;

var req = new Request(sortBy: null, direction: SortDirection.Desc, currentPage: 3);

var q = WebSerializer.ToQueryString(req);

//await httpClient.GetAsync("/sort?"+ q);
Console.WriteLine("/sort?"+ q);
// expected: /sort?direction=Desc&currentPage=3
// actual: /sort?&direction=Desc&currentPage=3

public record Request(
    [property: DataMember(Order = 0)] string? sortBy,
    SortDirection direction,
    int currentPage
);

public enum SortDirection
{
    Default,
    Asc,
    Desc
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the WebSerializer.ToQueryString entry point and reproduce the provided Request example, where the first property is null. Add a regression test for the expected query string without a leading ampersand, then verify the existing serialization tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.