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

fix: title empty if AddSegment is not called #14295

Merged
merged 14 commits into from
Jan 15, 2024

Conversation

PiemP
Copy link
Contributor

@PiemP PiemP commented Sep 8, 2023

Fixes #14284

@hishamco
Copy link
Member

Can you add a unit tests for this?

@PiemP
Copy link
Contributor Author

PiemP commented Sep 11, 2023

Can you add a unit tests for this?

I try....pls be patient with me :D

@PiemP
Copy link
Contributor Author

PiemP commented Sep 11, 2023

Test added... I could ask to you to give me a feeback about a discussion that I have open a month ago? I don't link it here because is something completely off topic.

Thank you

PS. Is something that seem simple...

@hishamco
Copy link
Member

Thanks again @PiemP

@hishamco
Copy link
Member

There's no fail in the build now

@Skrypt
Copy link
Contributor

Skrypt commented Sep 11, 2023

Make sure to not break the use case where someone wants to reset the page title by intentionally passing a string empty to RenderTitleSegments.

@PiemP
Copy link
Contributor Author

PiemP commented Sep 11, 2023

Make sure to not break the use case where someone wants to reset the page title by intentionally passing a string empty to RenderTitleSegments.

What do you intend with reset the page title? I have look at RazorPage.cs and Page.cs in the first case passing the empty string cause the print of the _title property of the PageTitleBuilder, in the second case this cause the reset of the _title to null and the regeneration of the title from the _titleParts (but in this case we add a separator to the end of the string).

Would you like that I make RenderTitleSegments works in the same way when pass an empty string?

@jtkech
Copy link
Member

jtkech commented Sep 11, 2023

See #14284 (comment)

@PiemP
Copy link
Contributor Author

PiemP commented Sep 13, 2023

converted to draft see #14284 (comment)

@jtkech
Copy link
Member

jtkech commented Sep 13, 2023

@PiemP So based on our discussion, see #14284 (comment), here my suggestion.

    private HtmlContentBuilder _title;
    ...
    ...

    public IHtmlContent GenerateTitle(IHtmlContent separator)
    {
        ...
        ...

        if (_title is { Count: > 0 })
        {
            return _title;
        }

        ...
        ...

@PiemP
Copy link
Contributor Author

PiemP commented Sep 14, 2023

Have I to remove HtmlContentExtensions or exist some interest around it?

@jtkech
Copy link
Member

jtkech commented Sep 14, 2023

Yes for now you can remove the extension and only use the mentioned changes.

Otherwise would need to be optimized, for example by using a ZStringWriter.

@PiemP
Copy link
Contributor Author

PiemP commented Sep 14, 2023

For the tests purpose I prefer to maintain it if it's possible. Why exists 2 ZStringWriter? (one in OrchardCore.Abstractions.Pooling and one in Cysharp.Text)

@jtkech
Copy link
Member

jtkech commented Sep 14, 2023

Maybe would need to be named .ToString().

But not sure it's good to encourage people to use it.

If you need it in the tests, why not just using a dedicated private method in the test class.

fix: removed HtmlContentExtension, avoid unwant use of it
fix: changed tests code to use a private version of extension removed
@PiemP PiemP marked this pull request as ready for review September 14, 2023 08:21
@sebastienros
Copy link
Member

Can we replace this code:

https://github.com/OrchardCMS/OrchardCore/pull/14295/files#diff-11e828c0a0bb3d4f6e17cbd3033ee185913d21d718955e3cee3fee161b87fca4R61-R66

by

            if (_titleParts.Count == 0)
            {
                return HtmlString.Empty;
            }

            // _titleParts.Count * 2 because we add a separator for each entry
            var htmlContentBuilder = new HtmlContentBuilder(_titleParts.Count * 2);

fix: init HtmlContentBuilder  with a size
@PiemP PiemP requested a review from hishamco October 9, 2023 14:50
@Piedone
Copy link
Member

Piedone commented Jan 14, 2024

Is this something you'd like to revisit any time soon @PiemP? Or perhaps @hishamco you can finish the nits so we can merge this, since otherwise it's all approved?

@PiemP
Copy link
Contributor Author

PiemP commented Jan 15, 2024

😅 ... maybe I have understand the changes requested by @hishamco ... sorry guys I'm pretty new to the things related to tests ... hope to have done all right.

@hishamco
Copy link
Member

I might revise this one

@Piedone
Copy link
Member

Piedone commented Jan 15, 2024

Great, thank you!

@Piedone Piedone merged commit 6c1736d into OrchardCMS:main Jan 15, 2024
3 checks passed
Skrypt pushed a commit that referenced this pull request Jan 25, 2024
* fix: title empty if AddSegment is not called

* style: renamed extension file and class

* style: sort usign, remove extra line

* test: added tests for PageTitleBuilder

* test: removed empty lines, String.Empty

* style: added const in test, line and string.Empty

* fix: use different check for empty title

fix: removed HtmlContentExtension, avoid unwant use of it
fix: changed tests code to use a private version of extension removed

* fix: moved HtmlContentBuilder in a best position

fix: init HtmlContentBuilder  with a size

* fix: comment, using var

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

---------

Co-authored-by: Hisham Bin Ateya <[email protected]>
hishamco added a commit that referenced this pull request Feb 1, 2024
* fix: title empty if AddSegment is not called

* style: renamed extension file and class

* style: sort usign, remove extra line

* test: added tests for PageTitleBuilder

* test: removed empty lines, String.Empty

* style: added const in test, line and string.Empty

* fix: use different check for empty title

fix: removed HtmlContentExtension, avoid unwant use of it
fix: changed tests code to use a private version of extension removed

* fix: moved HtmlContentBuilder in a best position

fix: init HtmlContentBuilder  with a size

* fix: comment, using var

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

---------

Co-authored-by: Hisham Bin Ateya <[email protected]>
urbanit pushed a commit to urbanit/OrchardCore that referenced this pull request Mar 18, 2024
* fix: title empty if AddSegment is not called

* style: renamed extension file and class

* style: sort usign, remove extra line

* test: added tests for PageTitleBuilder

* test: removed empty lines, String.Empty

* style: added const in test, line and string.Empty

* fix: use different check for empty title

fix: removed HtmlContentExtension, avoid unwant use of it
fix: changed tests code to use a private version of extension removed

* fix: moved HtmlContentBuilder in a best position

fix: init HtmlContentBuilder  with a size

* fix: comment, using var

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

* Update test/OrchardCore.Tests/DisplayManagement/Title/PageTitleBuilderTests.cs

---------

Co-authored-by: Hisham Bin Ateya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PageTitleBuilder: empty value, GenerateTitle doesn't work as expected
7 participants