summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.travis.yml14
-rw-r--r--CHANGELOG.md4
-rw-r--r--Gemfile9
-rw-r--r--README.md2
-rw-r--r--axlsx.gemspec2
-rw-r--r--lib/axlsx/version.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb6
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb4
-rw-r--r--test/workbook/worksheet/tc_cell.rb25
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb34
10 files changed, 60 insertions, 42 deletions
diff --git a/.travis.yml b/.travis.yml
index 38a3d013..465df230 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
language: ruby
sudo: required
-dist: trusty
-group: beta
+dist: bionic
+group: edge
cache: bundler
bundler_args: --without profile
@@ -19,13 +19,12 @@ matrix:
- rvm: 2.5.8
- rvm: 2.6.6
- rvm: 2.7.1
- - rvm: rbx-3
+ - rvm: 3.0.0
- rvm: jruby-19mode
- rvm: jruby-9.1.17.0
- rvm: ruby-head
- rvm: jruby-head
allow_failures:
- - rvm: rbx-3
- rvm: ruby-head
- rvm: jruby-9.1.17.0
- rvm: jruby-head
@@ -34,9 +33,4 @@ env:
global:
- JRUBY_OPTS="-Xcli.debug=true --debug"
-# https://github.com/jruby/jruby/wiki/FAQs#why-is-jruby-so-slow-to-install-via-rvm
-# https://docs.travis-ci.com/user/installing-dependencies#Installing-Packages-with-the-APT-Addon
-addons:
- apt:
- packages:
- - haveged
+# https://github.com/jruby/jruby/wiki/FAQs#why-is-jruby-so-slow-to-install-via-rvm \ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index af3432c7..2dd0ebbd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,8 +2,12 @@ CHANGELOG
---------
- **Unreleased**
+
+- **December.7.20**: 3.0.3
+ - [PR #62](https://github.com/caxlsx/caxlsx/pull/62) - Fix edge cases in format detection for objects whose string representation made them look like numbers but the object didn’t respond to `#to_i` or `#to_f`.
- [PR #56](https://github.com/caxlsx/caxlsx/pull/56) - Add `zip_command` option to `#serialize` for faster serialization of large Excel files by using a zip binary
- [PR #54](https://github.com/caxlsx/caxlsx/pull/54) - Fix type detection for floats with out-of-rage exponents
+ - [I #67](https://github.com/caxlsx/caxlsx/issues/67) - Fix regression in worksheet name length enforcement: Some unicode characters were counted incorrectly, so that names that previously worked fine now stopped working. (This was introduced in 3.0.2)
- **July.16.20**: 3.0.2
- [I #51](https://github.com/caxlsx/caxlsx/issues/51) - Images do not import on Windows. IO read set explicitly to binary mode.
diff --git a/Gemfile b/Gemfile
index 91fc31db..4aa4c3d7 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,11 +9,4 @@ end
group :profile do
gem 'ruby-prof', :platforms => :ruby
-end
-
-platforms :rbx do
- gem 'rubysl'
- gem 'rubysl-test-unit'
- gem 'racc'
- gem 'rubinius-coverage', '~> 2.0'
-end
+end \ No newline at end of file
diff --git a/README.md b/README.md
index e9c1d4a3..ba4bf221 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# Caxlsx (Community Continued Version)
[![Build Status](https://travis-ci.com/caxlsx/caxlsx.svg?branch=master)](https://travis-ci.com/caxlsx/caxlsx)
+[![Gem
+Version](https://badge.fury.io/rb/caxlsx.svg)](http://badge.fury.io/rb/caxlsx)
## Notice: Community Axlsx Organization
diff --git a/axlsx.gemspec b/axlsx.gemspec
index d494782f..3f8a5008 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -24,6 +24,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'yard', "~> 0.9.8"
s.add_development_dependency 'kramdown', '~> 2.3'
s.add_development_dependency 'timecop', "~> 0.8.1"
- s.required_ruby_version = '~> 2.3'
+ s.required_ruby_version = '>= 2.3'
s.require_path = 'lib'
end
diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb
index eadd9e54..0731798b 100644
--- a/lib/axlsx/version.rb
+++ b/lib/axlsx/version.rb
@@ -1,5 +1,5 @@
module Axlsx
# The current version
- VERSION = "3.0.2"
+ VERSION = "3.0.3"
end
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 9b87b894..51a14494 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -451,11 +451,11 @@ module Axlsx
:time
elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
:boolean
- elsif v.to_s =~ Axlsx::NUMERIC_REGEX
+ elsif v.to_s =~ Axlsx::NUMERIC_REGEX && v.respond_to?(:to_i)
:integer
- elsif v.to_s =~ Axlsx::SAFE_FLOAT_REGEX
+ elsif v.to_s =~ Axlsx::SAFE_FLOAT_REGEX && v.respond_to?(:to_f)
:float
- elsif (matchdata = v.to_s.match(MAYBE_FLOAT_REGEX)) && (Float::MIN_10_EXP..Float::MAX_10_EXP).cover?(matchdata[:exp].to_i)
+ elsif (matchdata = v.to_s.match(MAYBE_FLOAT_REGEX)) && (Float::MIN_10_EXP..Float::MAX_10_EXP).cover?(matchdata[:exp].to_i) && v.respond_to?(:to_f)
:float
elsif v.to_s =~ Axlsx::ISO_8601_REGEX
:iso_8601
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index aae91947..9f3966f8 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -663,7 +663,9 @@ module Axlsx
def validate_sheet_name(name)
DataTypeValidator.validate :worksheet_name, String, name
- raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.bytesize > 31
+ # ignore first character (BOM) after encoding to utf16 because Excel does so, too.
+ character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2
+ raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > 31
raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char }
name = Axlsx::coder.encode(name)
sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name }
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index 7e21b8cb..04f6bed3 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -127,6 +127,31 @@ class TestCell < Test::Unit::TestCase
assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00'))
end
+ def test_cell_type_from_value_looks_like_number_but_is_not
+ mimic_number = Class.new do
+ def initialize(to_s_value)
+ @to_s_value = to_s_value
+ end
+
+ def to_s
+ @to_s_value
+ end
+ end
+
+ number_strings = [
+ '1',
+ '1234567890',
+ '1.0',
+ '1e1',
+ '0',
+ "1e#{Float::MIN_10_EXP}"
+ ]
+
+ number_strings.each do |number_string|
+ assert_equal(@c.send(:cell_type_from_value, mimic_number.new(number_string)), :string)
+ end
+ end
+
def test_cast_value
@c.type = :string
assert_equal(@c.send(:cast_value, 1.0), "1.0")
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 781f5250..734096b5 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -29,15 +29,28 @@ class TestWorksheet < Test::Unit::TestCase
assert_raises(ArgumentError) { @ws.name = 'foo?bar' }
end
+ def test_name_unique
+ assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) }
+ end
+
+ def test_name_unique_only_checks_other_worksheet_names
+ assert_nothing_raised { @ws.name = @ws.name }
+ assert_nothing_raised { Axlsx::Package.new.workbook.add_worksheet :name => 'Sheet1' }
+ 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 }
+ four_characters_for_excel = "\u{1F1EB 1F1F7}" # french flag emoji
+ assert_raises(ArgumentError, "name too long!") do
+ @ws.name = four_characters_for_excel + "x" * 28
+ end
+ assert_nothing_raised { @ws.name = "#{four_characters_for_excel}123456789012345678901234567" }
+ assert_nothing_raised { @ws.name = "123456789012345678901234567890…" }
+ assert_nothing_raised { @ws.name = "123456789012345678901234567890✔" }
end
def test_page_margins
@@ -460,21 +473,6 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(@ws.relationships.size, 4, "adding a pivot table adds 1 relationship")
end
-
- def test_name_unique
- assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) }
- end
-
- def test_name_unique_only_checks_other_worksheet_names
- assert_nothing_raised { @ws.name = @ws.name }
- assert_nothing_raised { Axlsx::Package.new.workbook.add_worksheet :name => 'Sheet1' }
- end
-
- def test_name_size
- assert_raise(ArgumentError, "name too long!") { @ws.name = Array.new(32, "A").join() }
- assert_nothing_raised { @ws.name = Array.new(31, "A").join() }
- end
-
def test_set_fixed_width_column
@ws.add_row ["mule", "donkey", "horse"], :widths => [20, :ignore, nil]
assert(@ws.column_info.size == 3, "a data item for each column")