Skip to content

Commit

Permalink
Add compatibility with --enable-frozen-string-literal
Browse files Browse the repository at this point in the history
Fix: #168
Ref: https://bugs.ruby-lang.org/issues/20205

Ruby 3.4 will emit deprecation warnings when mutating string
literals, and a future version is likely to make frozen string
literals the default.
  • Loading branch information
byroot committed Mar 28, 2024
1 parent fe11372 commit bd8d5ef
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0", "3.1", "3.2"]
ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
rubyopt: [""]
include:
ruby: "3.3"
rubyopt: "--enable-frozen-string-literal --debug-frozen-string-literal"

steps:
- name: Checkout code
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true

require 'zlib'
require 'securerandom'
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf/api.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true

module CombinePDF
module_function
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf/basic_writer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true
########################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
Expand Down
3 changes: 2 additions & 1 deletion lib/combine_pdf/decrypt.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true
########################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
Expand Down Expand Up @@ -137,7 +138,7 @@ def decrypt_AES(encrypted, encrypted_id, encrypted_generation, _encrypted_filter
object_key = @key.dup
object_key << [encrypted_id].pack('i')[0..2]
object_key << [encrypted_generation].pack('i')[0..1]
object_key << 'sAlT'.force_encoding(Encoding::ASCII_8BIT)
object_key << 'sAlT'.b
key_length = object_key.length < 16 ? object_key.length : 16

begin
Expand Down
2 changes: 2 additions & 0 deletions lib/combine_pdf/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module CombinePDF
class EncryptionError < StandardError
end
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf/filter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true
########################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf/fonts.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true
########################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf/page_methods.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true
########################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
Expand Down
2 changes: 1 addition & 1 deletion lib/combine_pdf/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _parse_
##########################################
elsif @scanner.scan(/\(/)
# warn "Found a literal string"
str = ''.force_encoding(Encoding::ASCII_8BIT)
str = ''.b
count = 1
while count > 0 && @scanner.rest?
scn = @scanner.scan_until(/[\(\)]/)
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf/pdf_protected.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true
########################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
Expand Down
3 changes: 2 additions & 1 deletion lib/combine_pdf/pdf_public.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- encoding : utf-8 -*-
########################################################
## frozen_string_literal: true
#######################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
## is subject to the same license.
Expand Down
1 change: 1 addition & 0 deletions lib/combine_pdf/renderer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module CombinePDF
################################################################
## These are common functions, used within the different classes
Expand Down
4 changes: 3 additions & 1 deletion lib/combine_pdf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module CombinePDF
VERSION = '1.0.26'.freeze
VERSION = '1.0.26'
end
2 changes: 1 addition & 1 deletion test/combine_pdf/renderer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_object(object)

def test_numeric_array_to_pdf
input = [1.234567, 0.000054, 5, -0.000099]
expected = "[1.234567 0.000054 5 -0.000099]".force_encoding('BINARY')
expected = "[1.234567 0.000054 5 -0.000099]".b
actual = TestRenderer.new.test_object(input)

assert_equal(expected, actual)
Expand Down

0 comments on commit bd8d5ef

Please sign in to comment.