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

String repr of Dimension is system culture sensitive #53

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

chrisbbe
Copy link

@chrisbbe chrisbbe commented Feb 18, 2025

Gotenberg do not support decimal numbers with comma decimal separator.

Summary by CodeRabbit

  • Chores

    • Updated internal configuration to standardize file formatting and manage ignored content.
  • Refactor

    • Improved numeric formatting for dimensions to ensure a consistent decimal display across all locales.
  • Tests

    • Added automated tests to validate HTML request processing and accurate handling of paper dimensions.

These updates enhance overall consistency and reliability while ensuring uniform behavior in document processing.

Gotenberg do not support decimal numbers with comma decimal separator.
Copy link

coderabbitai bot commented Feb 18, 2025

Walkthrough

The changes add new configuration rules to handle files with extensions such as .received, .verified, .json, .txt, and .xml by updating the .editorconfig settings. The .gitignore file is modified to exclude received files. New test classes are added for the HTML request builder and for dimension formatting, ensuring that numeric values use a dot as a decimal separator. A corresponding test project targeting .NET 9.0 has also been created and integrated into the solution. Additionally, the Dimension class was updated to use culture-invariant formatting in its string representation.

Changes

File(s) Summary
.editorconfig, .gitignore Added settings for files with extensions .received, .verified, .json, .txt, .xml and ignore patterns for .received.
Gotenberg.Sharp.Api.Client.Tests/.../HtmlRequestBuilderTests.cs
Gotenberg.Sharp.Api.Client.Tests/.../HtmlRequestBuilderTests.*.verified.txt
Added HTML request builder tests verifying paper dimensions with decimal values and ensuring use of dot as decimal separator.
lib/Domain/Dimensions/Dimension.cs
.../DimensionTests.cs
Updated Dimension's ToString() to use InvariantCulture and introduced tests confirming correct formatting (dot separator).
Gotenberg.Sharp.Api.Client.Tests.csproj
GotenbergSharpApiClient.sln
Introduced new .NET 9.0 testing project with required package references and integrated it into the solution.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant HtmlRequestBuilder
    Test->>HtmlRequestBuilder: Create instance
    HtmlRequestBuilder->>HtmlRequestBuilder: Add HTML content and parameters (scale, paper dimensions, etc.)
    HtmlRequestBuilder->>Test: Build API request message
    Test->>Test: Verify correct formatting and decimal separator
Loading
sequenceDiagram
    participant Test
    participant Dimension
    Test->>Dimension: Instantiate with value (e.g., 11.7)
    Dimension->>Dimension: Convert value to string using InvariantCulture
    Dimension-->>Test: Return formatted string "11.7in"
Loading

Poem

I'm a rabbit hopping with cheer,
New configs and tests have appeared,
From editor rules to test suite play,
Decimal dots now lead the way.
With each code hop, I dance and rhyme—
A PR celebration, sweet as thyme!
🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
Gotenberg.Sharp.Api.Client.Tests/Domain/Dimensions/DimensionTests.cs (1)

20-31: LGTM! Well-structured test case.

The test effectively verifies the culture-invariant decimal separator formatting.

Consider adding more test cases to cover:

  • Large numbers (e.g., 1234.5678)
  • Small decimals (e.g., 0.001)
  • Whole numbers (e.g., 42)
lib/Domain/Dimensions/Dimension.cs (1)

93-93: Consider using culture-invariant parsing.

The Parse method should also use CultureInfo.InvariantCulture to ensure consistent parsing of decimal values.

-        var value = double.Parse(match.Groups[1].Value);
+        var value = double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
Gotenberg.Sharp.Api.Client.Tests/Gotenberg.Sharp.Api.Client.Tests.csproj (1)

24-26: Using Directive Inclusion – Verify Necessity.
The <Using Include="Xunit"/> entry is included here. Although implicit usings are enabled, if explicit global usings for xUnit are intended, please confirm that this aligns with your coding conventions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7287351 and acd6680.

📒 Files selected for processing (8)
  • .editorconfig (1 hunks)
  • .gitignore (1 hunks)
  • Gotenberg.Sharp.Api.Client.Tests/Domain/Builders/HtmlRequestBuilderTests.ToApiRequestMessage_PaperDimensionWithDecimal_NumbersUsesDotAsDecimalSeparator_Test.verified.txt (1 hunks)
  • Gotenberg.Sharp.Api.Client.Tests/Domain/Builders/HtmlRequestBuilderTests.cs (1 hunks)
  • Gotenberg.Sharp.Api.Client.Tests/Domain/Dimensions/DimensionTests.cs (1 hunks)
  • Gotenberg.Sharp.Api.Client.Tests/Gotenberg.Sharp.Api.Client.Tests.csproj (1 hunks)
  • GotenbergSharpApiClient.sln (2 hunks)
  • lib/Domain/Dimensions/Dimension.cs (2 hunks)
🔇 Additional comments (15)
Gotenberg.Sharp.Api.Client.Tests/Domain/Builders/HtmlRequestBuilderTests.cs (1)

20-38: LGTM! Comprehensive integration test.

The test effectively verifies that decimal dimensions are correctly formatted in the API request content, with good use of the Verify framework for snapshot testing.

GotenbergSharpApiClient.sln (1)

13-48: LGTM! Test project properly configured.

The test project is correctly integrated into the solution with all necessary build configurations.

lib/Domain/Dimensions/Dimension.cs (1)

17-17: LGTM! Culture-invariant string formatting implemented correctly.

The use of CultureInfo.InvariantCulture ensures consistent decimal formatting regardless of system culture.

Also applies to: 149-152

Gotenberg.Sharp.Api.Client.Tests/Gotenberg.Sharp.Api.Client.Tests.csproj (4)

1-8: Project Configuration is Correct and Modern.
The <PropertyGroup> properly targets .NET 9.0 and enables implicit usings and nullable reference types. Marking the project as not packable is appropriate for a test project.


10-14: Coverlet Package Reference is Set Up Appropriately.
The reference to coverlet.collector has correctly configured <PrivateAssets> and <IncludeAssets>, ensuring it does not leak to downstream projects.


15-21: Unit Testing Packages Configuration Looks Solid.
The additional package references for Microsoft.NET.Test.Sdk, Verify.Xunit, xunit, and xunit.runner.visualstudio are correctly specified with appropriate versions and asset protection where necessary.


28-30: Project Reference is Correctly Configured.
The new test project references the main library via <ProjectReference>, ensuring that tests will run against the current implementation of Gotenberg.Sharp.Api.Client.

Gotenberg.Sharp.Api.Client.Tests/Domain/Builders/HtmlRequestBuilderTests.ToApiRequestMessage_PaperDimensionWithDecimal_NumbersUsesDotAsDecimalSeparator_Test.verified.txt (6)

1-4: Scale Parameter is Correctly Specified.
The test file begins with the expected headers and a value of 1 for the scale parameter. This is appropriate and in line with test expectations.


5-8: Paper Width Uses Dot as Decimal Separator.
The paperWidth value of 8.5in clearly uses a dot as the decimal separator, which meets the requirements imposed by the Gotenberg service.


9-12: Paper Height Uses Dot as Decimal Separator.
The paperHeight value of 12.2in confirms the correct formatting for decimal numbers. This ensures that the system’s culture settings do not lead to commas in the representation.


13-20: Margin Values are Uniform and Correct.
The margins (marginTop, marginBottom, marginLeft, marginRight) are consistently set to 1in, which is appropriate for maintaining uniformity in the document layout.


21-28: Boolean Parameters are Explicitly Defined.
Parameters such as landscape (False), preferCssPageSize (False), printBackground (False), omitBackground (False), generateDocumentOutline (False), failOnConsoleExceptions (False), and skipNetworkIdleEvent (False) are clearly specified. This explicitness ensures that the API request is built with the expected configuration.


29-61: HTML File Content is Minimal Yet Sufficient.
The inclusion of a simple HTML snippet (<h1>Hello</h1>) for the file upload portion serves well as a test fixture. It confirms that the builder can handle multipart form-data with both text and HTML content appropriately.

.editorconfig (1)

79-89: New Formatting Rules for Compound Extensions

The newly added section

# Verify settings
[*.{received,verified}.{json,txt,xml}]
charset = "utf-8-bom"
end_of_line = lf
indent_size = unset
indent_style = unset
insert_final_newline = false
tab_width = unset
trim_trailing_whitespace = false

clearly defines formatting rules for files that follow a compound extension pattern (for example, file.received.json or file.verified.xml). These rules are set to enforce consistency and help avoid culture-dependent issues such as the decimal separator problem, which is especially relevant when interfacing with services like Gotenberg.

One thing to verify is whether the selected glob pattern ([*.{received,verified}.{json,txt,xml}]) matches exactly the intended files. For example, if you also need to cover files with a single extension like .json (without a preceding identifier like "received" or "verified"), you might need to add extra sections or adjust the pattern. If this specificity is by design, the configuration is already well-structured.

.gitignore (1)

291-293: New Ignore Patterns for Received Files

The added ignore entries:

# Verify
*.received.*
*.received/

ensure that files (and directories) with a ".received" marker are not tracked by version control. This matches the intended approach to ignore files that are likely generated by external processes (such as Gotenberg outputs).

Please verify that these patterns cover all cases you intend to ignore—for instance, files with compound extensions like document.received.json and directories ending with .received. Also, check if case-sensitivity or any further variations need to be accounted for.

@chrisbbe chrisbbe changed the title String repr of Dimension is longer system culture sensitive String repr of Dimension is system culture sensitive Feb 20, 2025
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.

1 participant