SchrodingersGat / KiBoM

Configurable BoM generation tool for KiCad EDA (http://kicad.org/)
MIT License
350 stars 95 forks source link

Feature request: enclose path with quotes #159

Open sslupsky opened 2 years ago

sslupsky commented 2 years ago

Some hyperlinks contain paths with commas which is a problem within a CSV. I am wondering if it would be beneficial to enclose the path or link for the datasheet within quotes?

In the screenshot below, you can see an example of how this might cause a problem. In this example, vscode appends the fields after the datasheet into the datasheet link. Screen Shot 2021-10-01 at 2 30 15 PM

set-soft commented 2 years ago

Which Python is installed in your system? I tried the KiBoM code on Python 3.9 and it defaults to quoting=csv.QUOTE_MINIMAL This means you should get strings with the delimiter quoted. I tried this example (from Python manual):

import csv
with open('eggs.csv', 'w', newline='') as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=',', lineterminator="\n") # quotechar='|', quoting=csv.QUOTE_MINIMAL)
    spamwriter.writerow(['Spam'] * 5 + ['Baked, Beans'])
    spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])

And got:

$ cat eggs.csv 
Spam,Spam,Spam,Spam,Spam,"Baked, Beans"
Spam,Lovely Spam,Wonderful Spam

In KiBoM's code the file csv_writer.py writes the CSV output, the csv writer is initialized like this:

    writer = csv.writer(f, delimiter=delimiter, lineterminator="\n")

You could modify it to:

    writer = csv.writer(f, delimiter=delimiter, lineterminator="\n", quoting=csv.QUOTE_ALL)

This will force quotes in all fields.