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

Ignores/Strips CSV cell content when parsing CSV cells starting with "#" #2076

Closed
rrrix opened this issue Jun 20, 2024 · 2 comments
Closed
Labels

Comments

@rrrix
Copy link

rrrix commented Jun 20, 2024

When parsing a CSV file that has a cell starting with the # character, it will set that cell to nil (or null).

Given the following CSV example:

Input CSV

"color","hex"
"white","#ffffff"
"black","#000000"
"red","#ff0000"
"green","#00ff00"
"blue","#0000ff"
"notblack","000000"
"kcalb","000000#"

Actual Behavior

Using yq to pretty print it right back as CSV:

$ yq . colors.csv

color,hex
white,
black,
red,
green,
blue,
notblack,000000
kcalb,000000#

Or to JSON:

$ yq -ojson . colors.csv

Click to expand...
[
  {
    "color": "white",
    "hex": null
  },
  {
    "color": "black",
    "hex": null
  },
  {
    "color": "red",
    "hex": null
  },
  {
    "color": "green",
    "hex": null
  },
  {
    "color": "blue",
    "hex": null
  },
  {
    "color": "notblack",
    "hex": 0
  },
  {
    "color": "kcalb",
    "hex": "000000#"
  }
]

Expected Behavior

Running yq . colors.csv should produce the output unchanged.

$ yq --version
yq (https://github.com/mikefarah/yq/) version v4.44.2
$ uname -sm
Darwin x86_64

Installed via Homebrew.

@mikefarah
Copy link
Owner

Thanks for raising, will fix in the next release.

Note that when fixed, you will likely want to pass in --csv-auto-parse=f because by default yq parses csv values, and the "#" symbol will be interpreted as a comment.

@mikefarah
Copy link
Owner

Fixed in 4.44.3

tmeijn pushed a commit to tmeijn/dotfiles that referenced this issue Aug 10, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [mikefarah/yq](https://github.com/mikefarah/yq) | patch | `v4.44.2` -> `v4.44.3` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>mikefarah/yq (mikefarah/yq)</summary>

### [`v4.44.3`](https://github.com/mikefarah/yq/releases/tag/v4.44.3)

[Compare Source](mikefarah/yq@v4.44.2...v4.44.3)

-   Fixed upper-case file extension detection, Thanks [@&#8203;ryenus](https://github.com/ryenus) ([#&#8203;2121](mikefarah/yq#2121))
    -   Log printing follow no-colors flag [#&#8203;2082](mikefarah/yq#2082)
    -   Skip and warn when interpolating strings and theres a unclosed bracket [#&#8203;2083](mikefarah/yq#2083)
    -   Fixed CSV content starting with # issue [#&#8203;2076](mikefarah/yq#2076)
    -   Bumped dependencies

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants