|
4 | 4 | "encoding/xml" |
5 | 5 | "fmt" |
6 | 6 | "path/filepath" |
| 7 | + "strings" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | _ "image/jpeg" |
@@ -1099,6 +1100,25 @@ func TestAdjustDataValidations(t *testing.T) { |
1099 | 1100 | f.Sheet.Delete("xl/worksheets/sheet1.xml") |
1100 | 1101 | f.Pkg.Store("xl/worksheets/sheet1.xml", MacintoshCyrillicCharset) |
1101 | 1102 | assert.EqualError(t, f.adjustDataValidations(nil, "Sheet1", columns, 0, 0, 1), "XML syntax error on line 1: invalid UTF-8") |
| 1103 | + |
| 1104 | + t.Run("for_escaped_data_validation_rules_formula", func(t *testing.T) { |
| 1105 | + f := NewFile() |
| 1106 | + _, err := f.NewSheet("Sheet2") |
| 1107 | + assert.NoError(t, err) |
| 1108 | + dv := NewDataValidation(true) |
| 1109 | + dv.Sqref = "A1" |
| 1110 | + assert.NoError(t, dv.SetDropList([]string{"option1", strings.Repeat("\"", 4)})) |
| 1111 | + ws, ok := f.Sheet.Load("xl/worksheets/sheet1.xml") |
| 1112 | + assert.True(t, ok) |
| 1113 | + assert.NoError(t, f.AddDataValidation("Sheet1", dv)) |
| 1114 | + // The double quote symbol in none formula data validation rules will be escaped in the Kingsoft WPS Office |
| 1115 | + formula := strings.ReplaceAll(fmt.Sprintf("\"option1, %s", strings.Repeat("\"", 9)), "\"", """) |
| 1116 | + ws.(*xlsxWorksheet).DataValidations.DataValidation[0].Formula1.Content = formula |
| 1117 | + f.RemoveCol("Sheet2", "A") |
| 1118 | + dvs, err := f.GetDataValidations("Sheet1") |
| 1119 | + assert.NoError(t, err) |
| 1120 | + assert.Equal(t, formula, dvs[0].Formula1) |
| 1121 | + }) |
1102 | 1122 | } |
1103 | 1123 |
|
1104 | 1124 | func TestAdjustDrawings(t *testing.T) { |
|
0 commit comments