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

When outputting to existing file, it is not truncated #329

Closed
jimklimov opened this issue Jul 20, 2023 · 1 comment · Fixed by #315
Closed

When outputting to existing file, it is not truncated #329

jimklimov opened this issue Jul 20, 2023 · 1 comment · Fixed by #315

Comments

@jimklimov
Copy link
Contributor

While running dev-tests with different builds of the tool, I've got invalid JSONs, looking like this (at where the parser reading them back complained):

...
    {
      "ref": "pkg:maven/io.cucumber/[email protected]?type=jar",
      "dependsOn": [
        "pkg:maven/io.cucumber/[email protected]?type=jar",
        "pkg:maven/io.cucumber/[email protected]?type=jar"
      ]
    },
    {
      "ref": "pkg:maven/io.cucumber/[email protected]?type=jar",
      "dependsOn": [
        "pkg:maven/io.cucumber/[email protected]?type=jar"
      ]
    }
  ]
}ent": "3f135e04c0bd0db2f5f00b3221aab2dc968051427324b6f037c7de75cce388eabb13ef27943e17b8646640cbfd908325d099b641d1c19a29b609db8a083324fa"
        }
      ],
      "licenses": [
        {
          "license": {
            "id": "Apache-2.0"
          }
        }
      ],

Digging a bit more into this, the culprit seems to be here:

using var stream = filename == null ? Console.OpenStandardOutput() : File.OpenWrite(filename);

According to https://stackoverflow.com/questions/3653132/file-openwrite-appends-instead-of-wiping-contents the File.Create() should be used instead of File.OpenWrite() which here (mis-)behaves correctly according to its spec.

jimklimov added a commit to jimklimov/cyclonedx-cli that referenced this issue Jul 20, 2023
jimklimov added a commit to jimklimov/cyclonedx-cli that referenced this issue Jul 21, 2023
@andreas-hilti
Copy link
Contributor

This is actually a duplicate of #255, for which I have summitted a PR as well (#315), but it hasn't been approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants