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

CSV.Create - Bug fix: Fixed issue with empty spaces in JSON property names #39

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

RikuVirtanen
Copy link
Contributor

@RikuVirtanen RikuVirtanen commented Oct 11, 2024

#38

[1.5.0] - 2024-10-11

Fixed

  • Fixed issue with JSON properties having spaces in property names.

Summary by CodeRabbit

Release Notes for Version 1.5.0

  • New Features

    • Improved handling of JSON properties with spaces during CSV creation.
    • Enhanced error handling for manually specified columns to prevent invalid input.
  • Bug Fixes

    • Resolved issues with JSON properties containing spaces, ensuring cleaner CSV output.
  • Tests

    • Added two new tests to verify correct handling of JSON with spaces in property names.
  • Chores

    • Updated version number to 1.5.0 in the project file.

Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

This pull request introduces version 1.5.0 of the Frends.CSV.Create project, released on October 11, 2024. It includes a fix for handling JSON properties with spaces in their names, ensuring they are processed correctly during CSV creation. Two new test methods are added to validate this behavior. Additionally, the Create.cs file has been modified to improve JSON path processing and error handling in the conversion methods. The project file reflects the updated version number.

Changes

File/Directory Change Summary
Frends.CSV.Create/CHANGELOG.md Added entry for version 1.5.0, detailing the fix for JSON properties with spaces.
Frends.CSV.Create/Frends.CSV.Create.UnitTests/UnitTests.cs Added methods CreateTest_JSONWithSpacesInPropertyNames and CreateTest_JSONWithSpacesInPropertyNames2 to test CSV creation with JSON properties containing spaces.
Frends.CSV.Create/Frends.CSV.Create/Create.cs Modified FlattenJson method for improved JSON path processing and updated JsonToCsvString for better error handling.
Frends.CSV.Create/Frends.CSV.Create/Frends.CSV.Create.csproj Updated version number from 1.4.0 to 1.5.0 in the project file.

Possibly related PRs

Poem

🐰 In the meadow where data flows,
A fix for spaces, as everyone knows.
CSVs now shine, neat and bright,
With tests to ensure they’re just right.
Hooray for the changes, let’s hop and play,
Version 1.5.0 is here to stay! 🌼


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 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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cbc9813 and 7d30e3f.

📒 Files selected for processing (4)
  • Frends.CSV.Create/CHANGELOG.md (1 hunks)
  • Frends.CSV.Create/Frends.CSV.Create.UnitTests/UnitTests.cs (1 hunks)
  • Frends.CSV.Create/Frends.CSV.Create/Create.cs (3 hunks)
  • Frends.CSV.Create/Frends.CSV.Create/Frends.CSV.Create.csproj (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Frends.CSV.Create/Frends.CSV.Create/Frends.CSV.Create.csproj
🧰 Additional context used
🪛 LanguageTool
Frends.CSV.Create/CHANGELOG.md

[duplication] ~4-~4: Possible typo: you repeated a word
Context: ... Changelog ## [1.5.0] - 2024-10-11 ### Fixed - Fixed issue with JSON properties having space...

(ENGLISH_WORD_REPEAT_RULE)

🔇 Additional comments (2)
Frends.CSV.Create/Frends.CSV.Create/Create.cs (2)

289-289: Approved: Correct handling of JSON properties with spaces

The modification on line 289 to child.Path.Replace("['", "").Replace("']", "") correctly removes brackets and quotes from JSON property paths with spaces, ensuring they are processed accurately. This effectively resolves the bug related to JSON properties containing spaces.


305-305: Approved: Consistent processing of JSON paths

The change on line 305 to jToken.Path.Replace("['", "").Replace("']", "") mirrors the adjustment made earlier and ensures consistent handling of JSON property paths with spaces. This aligns with the PR objective to fix issues with spaces in JSON property names.

Frends.CSV.Create/Frends.CSV.Create.UnitTests/UnitTests.cs Outdated Show resolved Hide resolved
Frends.CSV.Create/Frends.CSV.Create/Create.cs Outdated Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (3)
Frends.CSV.Create/Frends.CSV.Create.UnitTests/UnitTests.cs (3)

470-491: LGTM! Consider enhancing the test case.

The test method CreateTest_JSONWithSpacesInPropertyNames successfully verifies the handling of a JSON property with spaces in its name. It's a good start for testing this functionality.

Consider the following minor improvements:

  1. Remove the Console.WriteLine(result.CSV); statement on line 489, as it's not necessary for the test and may clutter the test output.
  2. Add an assertion to check result.Success before comparing the CSV content, to ensure the operation completed successfully.

Example:

Assert.IsTrue(result.Success);
Assert.AreEqual(expectedCsv, result.CSV);

493-518: LGTM! Well-structured test case.

The test method CreateTest_JSONWithSpacesInPropertyNames2 provides excellent coverage for handling JSON properties with and without spaces in their names. It addresses the suggestions from the previous review comment and verifies the correct CSV output for a more complex JSON input.

For consistency with other test methods in this class, consider moving the expectedCsv declaration right after the options declaration. This would group all the setup code together before the actual test execution.

Example:

var options = new Options() { };

var expectedCsv = $"property with spaces;normal_property;another property with spaces{Environment.NewLine}test test;value;123{Environment.NewLine}";

var result = CSV.Create(input, options, default);

Assert.IsTrue(result.Success);
Assert.AreEqual(expectedCsv, result.CSV);

470-518: Great job addressing the JSON property spaces issue!

The two new test methods, CreateTest_JSONWithSpacesInPropertyNames and CreateTest_JSONWithSpacesInPropertyNames2, effectively cover the handling of JSON properties with spaces in their names. These additions align well with the PR objective of fixing the issue with empty spaces in JSON property names.

The tests provide good coverage for both simple and complex scenarios, ensuring that the CSV creation process correctly handles and preserves spaces in property names. This should help prevent potential issues in data handling or processing when dealing with such JSON inputs.

To further strengthen the test suite, consider adding edge cases such as:

  1. JSON with nested objects containing properties with spaces
  2. JSON with array elements having properties with spaces
  3. JSON with properties that are entirely composed of spaces

These additional scenarios would provide even more comprehensive coverage for the space-handling functionality.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d30e3f and fcfc576.

📒 Files selected for processing (2)
  • Frends.CSV.Create/Frends.CSV.Create.UnitTests/UnitTests.cs (1 hunks)
  • Frends.CSV.Create/Frends.CSV.Create/Create.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Frends.CSV.Create/Frends.CSV.Create/Create.cs
🧰 Additional context used

@ttossavainen ttossavainen merged commit 1a04616 into main Oct 15, 2024
5 checks passed
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.

2 participants