From 5d3f4a9b0f8c9474459e174cf22aeb8252f444ab Mon Sep 17 00:00:00 2001 From: Ian Clarkson Date: Mon, 16 Dec 2019 09:17:41 -0800 Subject: Check size in bytes as opposed to string size - `size` returns length in characters, but doesn't factor in multibyte Unicode characters. By switching to `bytesize`, we check the relevant measure of how many bytes the worksheet name is. - Fixes https://github.com/randym/axlsx/issues/588 - Copy of PR against original axlsx (https://github.com/randym/axlsx/pull/589) --- test/workbook/worksheet/tc_worksheet.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index fa8832d8..781f5250 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -29,6 +29,17 @@ class TestWorksheet < Test::Unit::TestCase assert_raises(ArgumentError) { @ws.name = 'foo?bar' } end + def test_exception_if_name_too_long + assert_nothing_raised { @ws.name = 'x' * 31 } + assert_raises(ArgumentError) { @ws.name = 'x' * 32 } + end + + def test_exception_if_name_too_long_because_of_multibyte_characters + three_byte_character = "✔" + assert_nothing_raised { @ws.name = 'x' * 28 + three_byte_character} + assert_raises(ArgumentError) { @ws.name = 'x' * 29 + three_byte_character } + end + def test_page_margins assert(@ws.page_margins.is_a? Axlsx::PageMargins) end -- cgit v1.2.3