summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2023-05-22 09:49:26 +0200
committerGitHub <[email protected]>2023-05-22 09:49:26 +0200
commita1f99fbd453345547c87e4fb6dcae2849a5f5ed2 (patch)
tree2b3bfa1f74433c5252f96fdfc0f875c7c53ba39c
parent6a4b82def2e94b4811c38c37e606d426710d1e6c (diff)
parent5277073210c711a1ab84d2a0e4b3a2ad3c71e835 (diff)
downloadcaxlsx-a1f99fbd453345547c87e4fb6dcae2849a5f5ed2.tar.gz
caxlsx-a1f99fbd453345547c87e4fb6dcae2849a5f5ed2.zip
Merge pull request #239 from adamkiczula/bug/fix-sheet-by-name-encoding
Fix sheet_by_name for sheets with escaped characters
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/axlsx/workbook/workbook.rb4
-rw-r--r--test/workbook/tc_workbook.rb2
3 files changed, 5 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 92d3396f..cf7a02ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ CHANGELOG
- Added frozen string literals
- Fix `SimpleTypedList#to_a` and `SimpleTypedList#to_ary` returning the internal list instance
- Remove ability to set `u=` to true in favor of using :single or one of the other underline options
+ - Fix `Workbook#sheet_by_name` not returning sheets with encoded characters in the name
- **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/workbook.rb b/lib/axlsx/workbook/workbook.rb
index 1a2f0488..da36e9a0 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -221,8 +221,8 @@ module Axlsx
# @param [String] name The name of the sheet you are looking for
# @return [Worksheet] The sheet found, or nil
def sheet_by_name(name)
- index = @worksheets.index { |sheet| sheet.name == name }
- @worksheets[index] if index
+ encoded_name = Axlsx.coder.encode(name)
+ @worksheets.find { |sheet| sheet.name == encoded_name }
end
# Creates a new Workbook.
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index d85c17d9..b1cfdc71 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -47,8 +47,10 @@ class TestWorkbook < Test::Unit::TestCase
def test_sheet_by_name_retrieval
@wb.add_worksheet(:name => 'foo')
@wb.add_worksheet(:name => 'bar')
+ @wb.add_worksheet(:name => "testin'")
assert_equal('foo', @wb.sheet_by_name('foo').name)
+ assert_equal("testin&apos;", @wb.sheet_by_name("testin'").name)
end
def test_worksheet_empty_name