Csv.java

1
package com.rbctcsworld.ecommerce.common;
2
3
import java.util.List;
4
5
/** CSV that opens safely in a spreadsheet: every text cell quoted, formulas defused (OWASP CSV injection). */
6
public final class Csv {
7
8
    private Csv() {
9
    }
10
11
    /**
12
     * One text cell: quoted, inner quotes doubled. A value a spreadsheet would run as a formula
13
     * (=, +, -, @, tab, carriage return at the start) gets a leading apostrophe. null = empty cell.
14
     */
15
    public static String cell(String value) {
16 1 1. cell : removed conditional - replaced equality check with false → KILLED
        if (value == null) return "";
17
        String v = value;
18 3 1. cell : removed conditional - replaced comparison check with false → KILLED
2. cell : removed conditional - replaced equality check with false → KILLED
3. cell : changed conditional boundary → KILLED
        if (!v.isEmpty() && "=+-@\t\r".indexOf(v.charAt(0)) >= 0) v = "'" + v;
19 1 1. cell : replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::cell → KILLED
        return "\"" + v.replace("\"", "\"\"") + "\"";
20
    }
21
22
    /** Numbers as they are (so the spreadsheet can add them up), everything else as a text cell. */
23
    public static String value(Object v) {
24 1 1. value : removed conditional - replaced equality check with false → KILLED
        if (v == null) return "";
25 3 1. value : removed conditional - replaced equality check with false → KILLED
2. value : removed conditional - replaced equality check with false → KILLED
3. value : replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::value → KILLED
        if (v instanceof Number n) return n instanceof java.math.BigDecimal d ? d.toPlainString() : n.toString();
26 1 1. value : replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::value → KILLED
        return cell(v.toString());
27
    }
28
29
    /** One line, CRLF-terminated (RFC 4180). */
30
    public static String line(List<?> values) {
31
        StringBuilder s = new StringBuilder();
32 2 1. line : removed conditional - replaced comparison check with false → KILLED
2. line : changed conditional boundary → KILLED
        for (int i = 0; i < values.size(); i++) {
33 2 1. line : removed conditional - replaced comparison check with false → KILLED
2. line : changed conditional boundary → KILLED
            if (i > 0) s.append(',');
34
            s.append(value(values.get(i)));
35
        }
36 1 1. line : replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::line → KILLED
        return s.append("\r\n").toString();
37
    }
38
}

Mutations

16

1.1
Location : cell
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:textCellsAreQuotedAndFormulasDefused()]
removed conditional - replaced equality check with false → KILLED

18

1.1
Location : cell
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:textCellsAreQuotedAndFormulasDefused()]
removed conditional - replaced comparison check with false → KILLED

2.2
Location : cell
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:textCellsAreQuotedAndFormulasDefused()]
removed conditional - replaced equality check with false → KILLED

3.3
Location : cell
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:textCellsAreQuotedAndFormulasDefused()]
changed conditional boundary → KILLED

19

1.1
Location : cell
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:textCellsAreQuotedAndFormulasDefused()]
replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::cell → KILLED

24

1.1
Location : value
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:numbersStayNumbersSoASpreadsheetCanAddThemUp()]
removed conditional - replaced equality check with false → KILLED

25

1.1
Location : value
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:numbersStayNumbersSoASpreadsheetCanAddThemUp()]
removed conditional - replaced equality check with false → KILLED

2.2
Location : value
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:numbersStayNumbersSoASpreadsheetCanAddThemUp()]
removed conditional - replaced equality check with false → KILLED

3.3
Location : value
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:numbersStayNumbersSoASpreadsheetCanAddThemUp()]
replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::value → KILLED

26

1.1
Location : value
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:numbersStayNumbersSoASpreadsheetCanAddThemUp()]
replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::value → KILLED

32

1.1
Location : line
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:aLineEndsWithCrLf()]
removed conditional - replaced comparison check with false → KILLED

2.2
Location : line
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:aLineEndsWithCrLf()]
changed conditional boundary → KILLED

33

1.1
Location : line
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:aLineEndsWithCrLf()]
removed conditional - replaced comparison check with false → KILLED

2.2
Location : line
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:aLineEndsWithCrLf()]
changed conditional boundary → KILLED

36

1.1
Location : line
Killed by : com.rbctcsworld.ecommerce.common.CsvTest.[engine:junit-jupiter]/[class:com.rbctcsworld.ecommerce.common.CsvTest]/[method:aLineEndsWithCrLf()]
replaced return value with "" for com/rbctcsworld/ecommerce/common/Csv::line → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support