corvus-dotnet / Corvus.UriTemplates

Low-allocation URI Template parsing and resolution, supporting the Tavis.UriTemplates API.
Apache License 2.0
15 stars 0 forks source link

Partially resolving one of multiple query parameters results in malformed template. #79

Closed wertzui closed 1 year ago

wertzui commented 1 year ago

When resolving one of multiple query parameters, the result is missing {&

var template = new UriTemplate("https://example.org/{?foo,bar}", true);
template.AddParameter("foo", 42);
Console.WriteLine(template.Resolve());

Results in

https://example.org/?foo=42bar}

But should be

https://example.org/?foo=42{&bar}
HowardvanRooijen commented 1 year ago

Thanks very much for reporting this and for the repro. We'll take a look!

mwadams commented 1 year ago

Quick note verifying a repro.

I can verify that this is the current behaviour.

The reference implementation in Tavis.UriTemplates produces the same result with the equivalent code.

Tavis.UriTemplates.UriTemplate template2 = new("https://example.org/{?foo,bar}", true);
template2.SetParameter("foo", 42);
Console.WriteLine(template2.Resolve());
https://example.org/?foo=42bar}

There are no specs that validate this case.

mwadams commented 1 year ago

It seems that there is no proper support for "new style" partial template resolution in Tavis.UriTemplates.

I have added some code which produces non-malformed URI templates, but it breaks the multivariable template up into components to deal with the possibility of missing items "in the middle" of the list.

mwadams commented 1 year ago

This is resolved in https://github.com/corvus-dotnet/Corvus.UriTemplates/commit/8f539246c837da4f171bf929f79b18883dd7dacd

mwadams commented 1 year ago

Which I have accidentally pushed to main. Clearly the branch protection is not correct here!

I'll sort this out and issue a PR.

mwadams commented 1 year ago

@wertzui Thanks for the bug report; can you have a look at the PR and validate that it "works for you".