From 383195708d2c16c9fa132738c41ac895ac701a9e Mon Sep 17 00:00:00 2001 From: Koza Date: Wed, 12 Apr 2023 18:40:03 +0200 Subject: Fix warnings with Ruby 2.x --- lib/axlsx.rb | 2 +- lib/axlsx/workbook/worksheet/worksheet.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 9dba9144..0fd8260c 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -206,7 +206,7 @@ module Axlsx # See https://www.owasp.org/index.php/CSV_Injection for details. # @return [Boolean] def self.escape_formulas - @escape_formulas.nil? ? false : @escape_formulas + !defined?(@escape_formulas) || @escape_formulas.nil? ? false : @escape_formulas end # Sets whether to treat values starting with an equals sign as formulas or as literal strings. diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 38fb5254..b4cad5be 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -21,7 +21,7 @@ module Axlsx @sheet_protection = nil initialize_page_options(options) parse_options options - self.escape_formulas = wb.escape_formulas if @escape_formulas.nil? + self.escape_formulas = wb.escape_formulas unless defined? @escape_formulas @workbook.worksheets << self @sheet_id = index + 1 yield self if block_given? -- cgit v1.2.3 From aa1ef598f4ec5990cc5e9e43bf37b5e04cccdecc Mon Sep 17 00:00:00 2001 From: Koza Date: Wed, 12 Apr 2023 19:19:41 +0200 Subject: Fix missing URI.open for ruby < 2.5 --- lib/axlsx/util/mime_type_utils.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/axlsx/util/mime_type_utils.rb b/lib/axlsx/util/mime_type_utils.rb index 5a6ad38e..f0c3afb1 100644 --- a/lib/axlsx/util/mime_type_utils.rb +++ b/lib/axlsx/util/mime_type_utils.rb @@ -14,7 +14,11 @@ module Axlsx # @param [String] v URI # @return [String] File mime type def self.get_mime_type_from_uri(v) - Marcel::MimeType.for(URI.open(v)) + if URI.respond_to?(:open) + Marcel::MimeType.for(URI.open(v)) + else + Marcel::MimeType.for(URI.parse(v).open) + end end end end -- cgit v1.2.3 From c891d749bc4dbaf621cf7afeb70c3d08178df098 Mon Sep 17 00:00:00 2001 From: Koza Date: Wed, 12 Apr 2023 19:54:44 +0200 Subject: Mock out external image requests to make the CI more stable --- Gemfile | 1 + test/drawing/tc_pic.rb | 5 ++++- test/tc_helper.rb | 1 + test/util/tc_mime_type_utils.rb | 5 ++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 432b4503..fb69c977 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ group :test do gem 'rake' gem 'simplecov', '>= 0.14.1' gem 'test-unit' + gem 'webmock' end group :profile do diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb index 34f24eb3..21d3f931 100644 --- a/test/drawing/tc_pic.rb +++ b/test/drawing/tc_pic.rb @@ -2,13 +2,16 @@ require 'tc_helper.rb' class TestPic < Test::Unit::TestCase def setup + stub_request(:get, 'https://example.com/sample-image.png') + .to_return(body: File.new('examples/sample.png'), status: 200) + @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @test_img = @test_img_jpg = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" @test_img_png = File.dirname(__FILE__) + "/../fixtures/image1.png" @test_img_gif = File.dirname(__FILE__) + "/../fixtures/image1.gif" @test_img_fake = File.dirname(__FILE__) + "/../fixtures/image1_fake.jpg" - @test_img_remote_png = "https://via.placeholder.com/150.png" + @test_img_remote_png = "https://example.com/sample-image.png" @test_img_remote_fake = "invalid_URI" @image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?", :opacity => 5 @image_remote = ws.add_image :image_src => @test_img_remote_png, remote: true, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?", :opacity => 5 diff --git a/test/tc_helper.rb b/test/tc_helper.rb index af40a1e4..fb85870a 100644 --- a/test/tc_helper.rb +++ b/test/tc_helper.rb @@ -7,4 +7,5 @@ end require 'test/unit' require "timecop" +require 'webmock/test_unit' require "axlsx.rb" diff --git a/test/util/tc_mime_type_utils.rb b/test/util/tc_mime_type_utils.rb index 9d116931..52c49e2e 100644 --- a/test/util/tc_mime_type_utils.rb +++ b/test/util/tc_mime_type_utils.rb @@ -1,8 +1,11 @@ require 'tc_helper.rb' class TestMimeTypeUtils < Test::Unit::TestCase def setup + stub_request(:get, 'https://example.com/sample-image.png') + .to_return(body: File.new('examples/sample.png'), status: 200) + @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" - @test_img_url = "https://via.placeholder.com/150.png" + @test_img_url = "https://example.com/sample-image.png" end def teardown -- cgit v1.2.3 From b5546e784c91e35b447793d624028e2d520392a6 Mon Sep 17 00:00:00 2001 From: Koza Date: Wed, 12 Apr 2023 19:25:04 +0200 Subject: Version bump to 3.4.0 --- CHANGELOG.md | 2 ++ lib/axlsx/version.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e6fa749..cc5cdd3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ CHANGELOG --------- - **Unreleased** + +- **April.12.23**: 3.4.0 - [PR #186](https://github.com/caxlsx/caxlsx/pull/186) - Add `escape_formulas` to global, workbook, worksheet, row and cell levels, and standardize behavior. - [PR #186](https://github.com/caxlsx/caxlsx/pull/186) - `escape_formulas` should handle all [OWASP-designated formula prefixes](https://owasp.org/www-community/attacks/CSV_Injection). - Fix bug when calling `worksheet.add_border("A1:B2", nil)` diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index cf70e2e9..3f25c750 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -1,4 +1,4 @@ module Axlsx # The current version - VERSION = "3.3.0" + VERSION = "3.4.0" end -- cgit v1.2.3