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

setter and getter of Url.Search and Url.Hash is inconsistent #1019

Closed
5 tasks done
kzrnm opened this issue Dec 6, 2021 · 1 comment · Fixed by #1021
Closed
5 tasks done

setter and getter of Url.Search and Url.Hash is inconsistent #1019

kzrnm opened this issue Dec 6, 2021 · 1 comment · Fixed by #1021
Labels

Comments

@kzrnm
Copy link
Contributor

kzrnm commented Dec 6, 2021

Bug Report

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version of AngleSharp?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Css for CSS support)
  • Did you perform a search in the issues?

For more information, see the CONTRIBUTING guide.

Description

  • getter: If Url.Query is null, Url.Search start with '?', otherwise Url.Search is "".
  • setter: query value which does not start with '?'.

It is the same for Url.Hash.

Steps to Reproduce

Assigning url.Search to url.Search.

var url = new AngleSharp.Dom.Url("http://example.com/foo/bar?baz=1#foo");
url.Search = url.Search;
url.Hash = url.Hash;

Expected behavior: [What you expected to happen]

void Print(string? text)
{
    Console.WriteLine(text switch
    {
        null => "null",
        "" => "String.Empty",
        _ => text,
    });
}

var url = new AngleSharp.Dom.Url("http://example.com/foo/bar?baz=1#foo");
Print(url.ToString());               // http://example.com/foo/bar?baz=1#foo
Print(url.Fragment);                 // foo
Print(url.Hash);                     // #foo
Print(url.Query);                    // baz=1
Print(url.Search);                   // ?baz=1
Print(url.SearchParams.ToString());  // baz=1
url.Hash = url.Hash;
url.Search = url.Search;
Print(url.ToString());               // http://example.com/foo/bar?baz=1#foo
Print(url.Fragment);                 // foo
Print(url.Hash);                     // #foo
Print(url.Query);                    // baz=1
Print(url.Search);                   // ?baz=1
Print(url.SearchParams.ToString());  // baz=1

Actual behavior: [What actually happened]

var url = new AngleSharp.Dom.Url("http://example.com/foo/bar?baz=1#foo");
Print(url.Fragment);                 // foo
Print(url.Hash);                     // #foo
Print(url.ToString());               // http://example.com/foo/bar?baz=1#foo
Print(url.Query);                    // baz=1
Print(url.Search);                   // ?baz=1
url.Search = url.Search;
url.Hash = url.Hash;
Print(url.Fragment);                 // #foo
Print(url.Hash);                     // ##foo
Print(url.ToString());               // http://example.com/foo/bar?baz=1#foo
Print(url.Query);                    // ?baz=1
Print(url.Search);                   // ??baz=1

or

var url = new AngleSharp.Dom.Url("http://example.com/foo/bar?baz=1#foo");
Print(url.ToString());               // http://example.com/foo/bar?baz=1#foo
Print(url.Fragment);                 // foo
Print(url.Hash);                     // #foo
Print(url.Query);                    // baz=1
Print(url.Search);                   // ?baz=1
Print(url.SearchParams.ToString());  // baz=1
url.Search = url.Search;
url.Hash = url.Hash;
Print(url.ToString());               // http://example.com/foo/bar?baz=1#foo
Print(url.Fragment);                 // #foo
Print(url.Hash);                     // ##foo
Print(url.Query);                    // %3Fbaz=1
Print(url.Search);                   // ?%3Fbaz=1
Print(url.SearchParams.ToString());  // %3Fbaz=1

Environment details: [OS, .NET Runtime, ...]

Possible Solution

kzrnm@bc2e97e

The commit needs #1016.

@kzrnm kzrnm added the bug label Dec 6, 2021
@FlorianRappl
Copy link
Contributor

It should definitely be the first behavior; if Hash starts with # it should be Substring(1) and same for Search.

@kzrnm kzrnm mentioned this issue Dec 7, 2021
9 tasks
FlorianRappl added a commit that referenced this issue Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants