summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKoza <[email protected]>2023-09-26 11:33:36 +0200
committerKoza <[email protected]>2023-10-19 10:21:07 +0200
commit964d9800117196c0494d852d84d26613c9cc89f9 (patch)
tree155714420a73c814ebfd9d322a0fb4f06d357d80
parent57ddee52d3208a475ba32a78f814884fd7a1cf4c (diff)
downloadcaxlsx-964d9800117196c0494d852d84d26613c9cc89f9.tar.gz
caxlsx-964d9800117196c0494d852d84d26613c9cc89f9.zip
Fix data validations for none type validations to show warnings only
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/axlsx/workbook/worksheet/data_validation.rb12
-rw-r--r--test/workbook/worksheet/tc_data_validation.rb29
3 files changed, 34 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7896ea61..476db005 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ CHANGELOG
- Add 'SortState' and 'SortCondition' classes to the 'AutoFilter' class to add sorting to the generated file.
- [PR #189](https://github.com/caxlsx/caxlsx/pull/189) - Make `Axlsx::escape_formulas` true by default to mitigate [Formula Injection](https://www.owasp.org/index.php/CSV_Injection) vulnerabilities.
- [PR #269](https://github.com/caxlsx/caxlsx/pull/269) - Add optional interpolation points to icon sets
+ - [PR #304](https://github.com/caxlsx/caxlsx/pull/304) - Fix data validations for none type validations
- **April.23.23**: 3.4.1
- [PR #209](https://github.com/caxlsx/caxlsx/pull/209) - Revert characters other than `=` being considered as formulas.
diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb
index a84ab84d..a9e7ea9f 100644
--- a/lib/axlsx/workbook/worksheet/data_validation.rb
+++ b/lib/axlsx/workbook/worksheet/data_validation.rb
@@ -254,17 +254,15 @@ module Axlsx
attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type]
if [:whole, :decimal, :data, :time, :date, :textLength].include?(@type)
- attributes << [:operator, :formula1]
- attributes << [:formula2] if [:between, :notBetween].include?(@operator)
+ attributes << :operator << :formula1
+ attributes << :formula2 if [:between, :notBetween].include?(@operator)
elsif @type == :list
- attributes << [:showDropDown, :formula1]
+ attributes << :showDropDown << :formula1
elsif @type == :custom
- attributes << [:formula1]
- else
- attributes = []
+ attributes << :formula1
end
- attributes.flatten!
+ attributes
end
end
end
diff --git a/test/workbook/worksheet/tc_data_validation.rb b/test/workbook/worksheet/tc_data_validation.rb
index fa09b0ab..f411823e 100644
--- a/test/workbook/worksheet/tc_data_validation.rb
+++ b/test/workbook/worksheet/tc_data_validation.rb
@@ -239,6 +239,24 @@ class TestDataValidation < Test::Unit::TestCase
assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula1='=5/2'")
end
+ def test_none_to_xml
+ p = Axlsx::Package.new
+ @ws = p.workbook.add_worksheet name: "data_validation"
+ @ws.add_data_validation("A1", { type: :none,
+ showInputMessage: true, promptTitle: 'Be careful!',
+ prompt: 'This is a warning to be extra careful editing this cell' })
+
+ doc = Nokogiri::XML.parse(@ws.to_xml_string)
+
+ # test attributes
+ assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='1']/xmlns:dataValidation[@sqref='A1']
+ [@promptTitle='Be careful!'][@prompt='This is a warning to be extra careful editing this cell']
+ [@allowBlank=1][@showInputMessage=1][@type='none']").size)
+ assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='1']/xmlns:dataValidation[@sqref='A1']
+ [@promptTitle='Be careful!'][@prompt='This is a warning to be extra careful editing this cell']
+ [@allowBlank=1][@showInputMessage=1][@type='none']")
+ end
+
def test_multiple_datavalidations_to_xml
p = Axlsx::Package.new
@ws = p.workbook.add_worksheet name: "data_validation"
@@ -276,6 +294,15 @@ class TestDataValidation < Test::Unit::TestCase
def test_empty_attributes
v = Axlsx::DataValidation.new
- assert_nil(v.send(:get_valid_attributes))
+ assert_equal([:allowBlank,
+ :error,
+ :errorStyle,
+ :errorTitle,
+ :prompt,
+ :promptTitle,
+ :showErrorMessage,
+ :showInputMessage,
+ :sqref,
+ :type], v.send(:get_valid_attributes))
end
end