Skip to content

CSV exports: a part number, name or comment that starts with =, +, - or @ opens in a spreadsheet as a formula #12728

Closed

Description

@CamWight

Reproduced on: SolidCraft 0.40.0-rc.2, built from source at main 73e188d on Windows 11 x86_64, through solidcraft-cli run.

SolidCraft writes four kinds of CSV file: the bill of materials (assembly.bom), the parameters (parameters.export), the bend table (sheet.export_bend_table) and motion samples (motion.export). Their text fields come from the design: part numbers, descriptions, revisions, names, expressions and comments. A spreadsheet reads a field that starts with =, +, - or @ as a formula. So these files can open in a spreadsheet with values that aren't the design's: a part numbered =1+1 shows as 2. A design received from someone else can put a formula into the spreadsheet of whoever exports its BOM. This is a hardening change: the fix keeps such a field as text.

Steps

{"commands":[
 {"command":"component.create","params":{"name":"Shim"}},
 {"command":"solid.box","params":{"length":40,"width":20,"height":3}},
 {"command":"component.activate","params":{"component":0}},
 {"command":"component.metadata.set","params":{"component":"Shim","part_number":"=1+1","description":"-5 mm shim","revision":"@SUM(1,1)"}},
 {"command":"assembly.bom","params":{"path":"bom.csv"}},
 {"command":"parameters.add","params":{"name":"gap","expression":"=5","comment":"+2 for the fit"}},
 {"command":"parameters.export","params":{"format":"csv","path":"params.csv"}}
]}

Then open bom.csv and params.csv in a spreadsheet.

Expected

The spreadsheet shows each field as the design has it: =1+1, -5 mm shim, @SUM(1,1), =5, +2 for the fit.

Actual

Corrected 7 Nov: the first Actual came from a drawings build, not main. The files below are from main 73e188d (114 and 77 bytes). The quoting is the same; main's BOM file has 6 columns, not 8.

The files hold the fields as they are, with nothing to keep them text:

bom.csv:
"item","part_number","description","revision","count","definition"
"1","=1+1","-5 mm shim","@SUM(1,1)","1","Shim"

params.csv:
name,unit,expression,value,comment,favorite
gap,mm,=5,5,+2 for the fit,false

Quoting a field doesn't make it text: a spreadsheet takes the quotes off and then reads the field. What each program does with these fields:

  • Excel reads =, +, - and @ at the start as a formula (+, - and @ come from Lotus 1-2-3). =1+1 shows 2. -5 mm shim is read as the formula =-5 mm shim, which shows #NAME?.
  • LibreOffice Calc reads = as a formula when its Text Import's "Evaluate formulas" is on. That option has been off by default since 2021 (tdf#114878).
  • OWASP's CSV Injection page lists the same triggers, plus tab, CR, LF and the full-width = + - @. Its first mitigation is a ' before such a field, inside quotes.

I have no spreadsheet program on this computer, so the effects above come from OWASP's page, LibreOffice's help and Excel's long-documented formula entry, not from a screenshot.

Where it happens

Four writers, each with its own quoting, and none of them guards a formula:

  • crates/doc/src/params.rs:487 params_csv: quotes a field only when it holds ,, " or a line break.
  • crates/engine/src/cmd/bom.rs:402 quote: always quotes.
  • crates/engine/src/cmd/sheet.rs:1153: its own quote, always quotes.
  • crates/engine/src/cmd/motion.rs:854: doesn't quote. A , in an occurrence name becomes a space, and a " or a line break breaks the row.

A ; inside an unquoted parameter field also matters. Where a spreadsheet's separator is ; (much of Europe), the field splits into a new cell, and that cell can start with =.

Suggestion

One shared CSV field writer that all four use:

  • A text field that starts with a trigger gets a ' in front, as OWASP says.
  • A field that is a whole plain number (-5, +5, 1e-9) stays as it is. A spreadsheet reads it as that number, and a negative coordinate stays a number.
  • parameters.import takes the ' off again, so an exported =5 expression imports back as =5 (Accept a leading = in expressions, so a fillet radius can be =d3 (#4681) #4686).
  • ; and tab join the characters that make a field quoted.

Activity

  1. added
    needs-triage
    in progress
    on Nov 6, 2026
  2. github-actions commented on Nov 6, 2026

    @github-actions
    Contributor

    Claimed by @CamWight through #12729. The claim lapses after 14 days without pushes.

  3. CamWight commented on Nov 7, 2026

    @CamWight
    ContributorAuthor

    I've corrected the Actual section above. The first version showed the files from a drawings build, which writes 8 columns in the BOM file. The files there now come from main 73e188d, where the BOM file has 6 columns. The problem is the same in both builds: the fields that start with =, - or @ are written as they are. I also fixed one line number: bom.rs:402, not 401.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in progressneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions