Skip to content

Double quote delimiter in Import-Csv #7110

Closed

Description

@iSazonov

Why double quote delimiter has a special behavior (skipping columns) in Import-Csv?
Is this expected/documented/RFC-defined behavior?

# Input 1.csv
# a1""a3
# v1"v2"v3

Import-csv .\1.csv -Delimiter '"'

# Output
a1 a3
-- --
v1 v3
# Input 2.csv
# a1,,a3
# v1,v2,v3

Import-csv .\2.csv -Delimiter ','

# Output
WARNING: One or more headers were not specified. Default names starting with "H" have been used in place of any missing headers.

a1 H1 a3
-- -- --
v1 v2 v3

Activity

  1. added
    Issue-Question
    on Jun 19, 2018
  2. iSazonov commented on Sep 20, 2018

    @iSazonov
    CollaboratorAuthor

    Steve Lee (@SteveL-MSFT) Have you any information about the special behavior? Is this side affect (bug) in the code or a standard?

  3. vexx32 commented on Sep 20, 2018

    @vexx32
    Collaborator

    That's probably somewhere between a "why would you use that as delimiter" and "special case that needs dealing with". CSV entries with spaces need to be enclosed with (usually) double quotes. I don't know if there's another possible enclosing character that can be relied upon, really (single quotes maybe?)

    The trouble with CSV is there isn't a concrete "standard" just a bunch of very similar implementations with some differences scattered throughout.

    But I've never seen a CSV with double quotes as delimiter before... I'd be of the inclination that it be treated as a reserved character and not be permitted as a delimiter for parsing at all, but...

  4. iSazonov commented on Sep 21, 2018

    @iSazonov
    CollaboratorAuthor

    But I've never seen a CSV with double quotes as delimiter before...

    The Issue is that we accept the delimiter and skip one column. So I'd expect that we either do not accept the delimiter or do not skip the column.

  5. vexx32 commented on Sep 21, 2018

    @vexx32
    Collaborator

    The former sounds perfectly fine to me, but I'm unsure if there's a valid reason to use a double quote as a delimiter.

  6. SteveL-MSFT commented on Sep 21, 2018

    @SteveL-MSFT
    Member

    Took a look at the code, as noted above, double quotes is a special character for containing whitespace so that this:

    "foo,bar","apple"

    becomes:

    foo,bar apple

    and not:

    foo bar apple

    So using " as the delimiter breaks this. I think that unless there's a real scenario to use the double quote as a delimiter, it's not worth making a change. Otherwise, we'd special case if double quote is used, you cannot have whitespace as part of a value.

  7. iSazonov commented on Sep 23, 2018

    @iSazonov
    CollaboratorAuthor

    Steve Lee (@SteveL-MSFT) My question is should we address scenario from my repo steps where we lost column?

  8. SteveL-MSFT commented on Sep 25, 2018

    @SteveL-MSFT
    Member

    Ilya (@iSazonov) there's probably a bug in the logic when double quotes are used as the delimiter as there's special code already to handle double quotes to preserve whitespace. I think the question is whether it's worthwhile to spend time investigating and fixing something that is a corner case.

  9. iSazonov commented on Sep 25, 2018

    @iSazonov
    CollaboratorAuthor

    I think the question is whether it's worthwhile to spend time investigating and fixing something that is a corner case.

    Yes, I think we can label this with Up-For-Grabs and Hackathon.

  10. added
    Up-for-Grabs
    Hacktoberfest
    on Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestIssue-QuestionResolution-FixedUp-for-GrabsWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions