Skip to content

Commit 7ce0f48

Browse files
authored
Merge branch 'main' into ct-_do_not_parse_multiline_strings
2 parents 22af13f + 7ecf751 commit 7ce0f48

18 files changed

+145
-84
lines changed

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/codeql-analysis.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ "main" ]
9+
schedule:
10+
- cron: '41 19 * * 2'
11+
12+
jobs:
13+
analyze:
14+
name: Analyze
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
contents: read
19+
security-events: write
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
language: [ 'ruby' ]
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
30+
# Initializes the CodeQL tools for scanning.
31+
- name: Initialize CodeQL
32+
uses: github/codeql-action/init@v2
33+
with:
34+
languages: ${{ matrix.language }}
35+
36+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
37+
# If this step fails, then you should remove it and run the build manually (see below)
38+
- name: Autobuild
39+
uses: github/codeql-action/autobuild@v2
40+
41+
- name: Perform CodeQL Analysis
42+
uses: github/codeql-action/analyze@v2

.github/workflows/test.yml

+27-29
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
matrix:
1515
ruby: [2.7]
1616
idna_mode: [native, pure]
17-
os: [ubuntu-18.04]
17+
os: [ubuntu-20.04]
1818
env:
1919
IDNA_MODE: ${{ matrix.idna_mode }}
2020
steps:
21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v3
2222

2323
- name: Install libidn
2424
run: sudo apt-get install libidn11-dev
@@ -46,15 +46,15 @@ jobs:
4646
fail-fast: false
4747
matrix:
4848
ruby: [2.7]
49-
os: [ubuntu-18.04]
49+
os: [ubuntu-20.04]
5050
env:
5151
BUNDLE_WITHOUT: development
5252
COVERALLS_SERVICE_NAME: github
5353
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5454
COVERALLS_DEBUG: true
5555
CI_BUILD_NUMBER: ${{ github.run_id }}
5656
steps:
57-
- uses: actions/checkout@v2
57+
- uses: actions/checkout@v3
5858

5959
- name: Install libidn
6060
run: sudo apt-get install libidn11-dev
@@ -86,45 +86,43 @@ jobs:
8686
- 2.7
8787
# quotes because of YAML gotcha: https://github.com/actions/runner/issues/849
8888
- '3.0'
89+
- 3.1
8990
- head
9091
- jruby-9.1
9192
- jruby-9.2
92-
- jruby-head
93-
# truffleruby-21.2 fails due to https://github.com/oracle/truffleruby/issues/2408
94-
- truffleruby-21.1
95-
- truffleruby-head
93+
- jruby-9.3
94+
- truffleruby-21.3
95+
- truffleruby-22.1
9696
os:
97-
- ubuntu-18.04
97+
- ubuntu-20.04
9898
gemfile:
9999
- Gemfile
100100
include:
101-
- { os: ubuntu-18.04, ruby: 2.7, gemfile: gemfiles/public_suffix_2.rb }
102-
- { os: ubuntu-18.04, ruby: 2.7, gemfile: gemfiles/public_suffix_3.rb }
103-
# Ubuntu 20.04
104-
- { os: ubuntu-20.04, ruby: 2.7 }
105-
- { os: ubuntu-20.04, ruby: '3.0' }
101+
- { os: ubuntu-20.04, ruby: 2.7, gemfile: gemfiles/public_suffix_2.rb }
102+
- { os: ubuntu-20.04, ruby: 2.7, gemfile: gemfiles/public_suffix_3.rb }
103+
- { os: ubuntu-20.04, ruby: 2.7, gemfile: gemfiles/public_suffix_4.rb }
104+
# Ubuntu
105+
- { os: ubuntu-18.04, ruby: 2.7 }
106+
- { os: ubuntu-22.04, ruby: 3.1 }
106107
# macOS
107-
- { os: macos-10.15, ruby: 2.7 }
108-
- { os: macos-10.15, ruby: '3.0' }
109-
- { os: macos-10.15, ruby: jruby }
110-
- { os: macos-10.15, ruby: truffleruby-21.1 }
111-
- { os: macos-11, ruby: 2.7 }
112-
- { os: macos-11, ruby: '3.0' }
113-
- { os: macos-11, ruby: jruby }
114-
- { os: macos-11, ruby: truffleruby-21.1 }
108+
- { os: macos-11, ruby: 3.1 }
109+
- { os: macos-12, ruby: 3.1 }
115110
# Windows
116-
- { os: windows-2019, ruby: 2.7 }
117-
- { os: windows-2019, ruby: '3.0' }
118-
- { os: windows-2019, ruby: jruby-9.1 }
119-
- { os: windows-2019, ruby: jruby-9.2 }
111+
- { os: windows-2019, ruby: 3.1 }
112+
- { os: windows-2022, ruby: 3.1 }
113+
- { os: windows-2022, ruby: jruby-9.3 }
120114
# allowed to fail
121-
- { os: ubuntu-18.04, ruby: jruby-head, allow-failure: true }
122-
- { os: ubuntu-18.04, ruby: truffleruby-head, allow-failure: true }
115+
- { os: ubuntu-20.04, ruby: jruby-head, gemfile: Gemfile, allow-failure: true }
116+
- { os: ubuntu-20.04, ruby: truffleruby-head, gemfile: Gemfile, allow-failure: true }
123117
env:
124118
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
125119
BUNDLE_WITHOUT: development:coverage
120+
# Workaround for Windows JRuby JDK issue
121+
# https://github.com/ruby/setup-ruby/issues/339
122+
# https://github.com/jruby/jruby/issues/7182#issuecomment-1112953015
123+
JAVA_OPTS: -Djdk.io.File.enableADS=true
126124
steps:
127-
- uses: actions/checkout@v2
125+
- uses: actions/checkout@v3
128126

129127
- name: Install libidn (Ubuntu)
130128
if: startsWith(matrix.os, 'ubuntu')

Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ group :test, :development do
2525
gem "rake", ">= 12.3.3"
2626
end
2727

28-
gem "idn-ruby", platform: :mri
28+
unless ENV["IDNA_MODE"] == "pure"
29+
gem "idn-ruby", platform: :mri
30+
end

addressable.gemspec

+9-11
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,30 @@ Gem::Specification.new do |s|
66
s.version = "2.8.0"
77

88
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9+
s.metadata = { "changelog_uri" => "https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md" } if s.respond_to? :metadata=
910
s.require_paths = ["lib".freeze]
1011
s.authors = ["Bob Aman".freeze]
1112
s.date = "2021-07-03"
1213
s.description = "Addressable is an alternative implementation to the URI implementation that is\npart of Ruby's standard library. It is flexible, offers heuristic parsing, and\nadditionally provides extensive support for IRIs and URI templates.\n".freeze
1314
s.email = "[email protected]".freeze
1415
s.extra_rdoc_files = ["README.md".freeze]
15-
s.files = ["CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE.txt".freeze, "README.md".freeze, "Rakefile".freeze, "addressable.gemspec".freeze, "benchmark".freeze, "coverage".freeze, "data".freeze, "data/unicode.data".freeze, "documentation".freeze, "gemfiles".freeze, "lib".freeze, "lib/addressable".freeze, "lib/addressable.rb".freeze, "lib/addressable/idna".freeze, "lib/addressable/idna.rb".freeze, "lib/addressable/idna/native.rb".freeze, "lib/addressable/idna/pure.rb".freeze, "lib/addressable/template.rb".freeze, "lib/addressable/uri.rb".freeze, "lib/addressable/version.rb".freeze, "spec".freeze, "spec/addressable".freeze, "spec/addressable/idna_spec.rb".freeze, "spec/addressable/net_http_compat_spec.rb".freeze, "spec/addressable/security_spec.rb".freeze, "spec/addressable/template_spec.rb".freeze, "spec/addressable/uri_spec.rb".freeze, "spec/spec_helper.rb".freeze, "specdoc".freeze, "tasks".freeze, "tasks/clobber.rake".freeze, "tasks/gem.rake".freeze, "tasks/git.rake".freeze, "tasks/metrics.rake".freeze, "tasks/profile.rake".freeze, "tasks/rspec.rake".freeze, "tasks/yard.rake".freeze, "tmp".freeze]
16+
s.files = ["CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE.txt".freeze, "README.md".freeze, "Rakefile".freeze, "data/unicode.data".freeze, "lib/addressable".freeze, "lib/addressable.rb".freeze, "lib/addressable/idna".freeze, "lib/addressable/idna.rb".freeze, "lib/addressable/idna/native.rb".freeze, "lib/addressable/idna/pure.rb".freeze, "lib/addressable/template.rb".freeze, "lib/addressable/uri.rb".freeze, "lib/addressable/version.rb".freeze, "spec/addressable".freeze, "spec/addressable/idna_spec.rb".freeze, "spec/addressable/net_http_compat_spec.rb".freeze, "spec/addressable/security_spec.rb".freeze, "spec/addressable/template_spec.rb".freeze, "spec/addressable/uri_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tasks/clobber.rake".freeze, "tasks/gem.rake".freeze, "tasks/git.rake".freeze, "tasks/metrics.rake".freeze, "tasks/profile.rake".freeze, "tasks/rspec.rake".freeze, "tasks/yard.rake".freeze]
1617
s.homepage = "https://github.com/sporkmonger/addressable".freeze
1718
s.licenses = ["Apache-2.0".freeze]
1819
s.rdoc_options = ["--main".freeze, "README.md".freeze]
19-
s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
20-
s.rubygems_version = "3.0.3".freeze
20+
s.required_ruby_version = Gem::Requirement.new(">= 2.2".freeze)
21+
s.rubygems_version = "3.3.7".freeze
2122
s.summary = "URI Implementation".freeze
2223

2324
if s.respond_to? :specification_version then
2425
s.specification_version = 4
26+
end
2527

26-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27-
s.add_runtime_dependency(%q<public_suffix>.freeze, [">= 2.0.2", "< 5.0"])
28-
s.add_development_dependency(%q<bundler>.freeze, [">= 1.0", "< 3.0"])
29-
else
30-
s.add_dependency(%q<public_suffix>.freeze, [">= 2.0.2", "< 5.0"])
31-
s.add_dependency(%q<bundler>.freeze, [">= 1.0", "< 3.0"])
32-
end
28+
if s.respond_to? :add_runtime_dependency then
29+
s.add_runtime_dependency(%q<public_suffix>.freeze, [">= 2.0.2", "< 6.0"])
30+
s.add_development_dependency(%q<bundler>.freeze, [">= 1.0", "< 3.0"])
3331
else
34-
s.add_dependency(%q<public_suffix>.freeze, [">= 2.0.2", "< 5.0"])
32+
s.add_dependency(%q<public_suffix>.freeze, [">= 2.0.2", "< 6.0"])
3533
s.add_dependency(%q<bundler>.freeze, [">= 1.0", "< 3.0"])
3634
end
3735
end

gemfiles/public_suffix_4.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
# Assumes this gemfile is used from the project root
4+
eval_gemfile "../Gemfile"
5+
6+
gem "public_suffix", "~> 4.0"

lib/addressable/idna.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# encoding:utf-8
43
#--
54
# Copyright (C) Bob Aman
65
#

lib/addressable/idna/native.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# encoding:utf-8
43
#--
54
# Copyright (C) Bob Aman
65
#

lib/addressable/idna/pure.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# encoding:utf-8
43
#--
54
# Copyright (C) Bob Aman
65
#

lib/addressable/template.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# encoding:utf-8
43
#--
54
# Copyright (C) Bob Aman
65
#

lib/addressable/uri.rb

+35-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# encoding:utf-8
43
#--
54
# Copyright (C) Bob Aman
65
#
@@ -38,20 +37,26 @@ class InvalidURIError < StandardError
3837
##
3938
# Container for the character classes specified in
4039
# <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>.
40+
#
41+
# Note: Concatenated and interpolated `String`s are not affected by the
42+
# `frozen_string_literal` directive and must be frozen explicitly.
43+
#
44+
# Interpolated `String`s *were* frozen this way before Ruby 3.0:
45+
# https://bugs.ruby-lang.org/issues/17104
4146
module CharacterClasses
4247
ALPHA = "a-zA-Z"
4348
DIGIT = "0-9"
4449
GEN_DELIMS = "\\:\\/\\?\\#\\[\\]\\@"
4550
SUB_DELIMS = "\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\="
46-
RESERVED = GEN_DELIMS + SUB_DELIMS
47-
UNRESERVED = ALPHA + DIGIT + "\\-\\.\\_\\~"
48-
PCHAR = UNRESERVED + SUB_DELIMS + "\\:\\@"
49-
SCHEME = ALPHA + DIGIT + "\\-\\+\\."
50-
HOST = UNRESERVED + SUB_DELIMS + "\\[\\:\\]"
51-
AUTHORITY = PCHAR + "\\[\\:\\]"
52-
PATH = PCHAR + "\\/"
53-
QUERY = PCHAR + "\\/\\?"
54-
FRAGMENT = PCHAR + "\\/\\?"
51+
RESERVED = (GEN_DELIMS + SUB_DELIMS).freeze
52+
UNRESERVED = (ALPHA + DIGIT + "\\-\\.\\_\\~").freeze
53+
PCHAR = (UNRESERVED + SUB_DELIMS + "\\:\\@").freeze
54+
SCHEME = (ALPHA + DIGIT + "\\-\\+\\.").freeze
55+
HOST = (UNRESERVED + SUB_DELIMS + "\\[\\:\\]").freeze
56+
AUTHORITY = (PCHAR + "\\[\\:\\]").freeze
57+
PATH = (PCHAR + "\\/").freeze
58+
QUERY = (PCHAR + "\\/\\?").freeze
59+
FRAGMENT = (PCHAR + "\\/\\?").freeze
5560
end
5661

5762
module NormalizeCharacterClasses
@@ -469,19 +474,13 @@ def self.unencode(uri, return_type=String, leave_encoded='')
469474
"Expected Class (String or Addressable::URI), " +
470475
"got #{return_type.inspect}"
471476
end
472-
uri = uri.dup
473-
# Seriously, only use UTF-8. I'm really not kidding!
474-
uri.force_encoding("utf-8")
475-
476-
unless leave_encoded.empty?
477-
leave_encoded = leave_encoded.dup.force_encoding("utf-8")
478-
end
479477

480-
result = uri.gsub(/%[0-9a-f]{2}/iu) do |sequence|
478+
result = uri.gsub(/%[0-9a-f]{2}/i) do |sequence|
481479
c = sequence[1..3].to_i(16).chr
482-
c.force_encoding("utf-8")
480+
c.force_encoding(sequence.encoding)
483481
leave_encoded.include?(c) ? sequence : c
484482
end
483+
485484
result.force_encoding("utf-8")
486485
if return_type == String
487486
return result
@@ -2440,30 +2439,35 @@ def defer_validation
24402439
def self.normalize_path(path)
24412440
# Section 5.2.4 of RFC 3986
24422441

2443-
return nil if path.nil?
2442+
return if path.nil?
24442443
normalized_path = path.dup
2445-
begin
2446-
mod = nil
2444+
loop do
24472445
mod ||= normalized_path.gsub!(RULE_2A, SLASH)
24482446

24492447
pair = normalized_path.match(RULE_2B_2C)
2450-
parent, current = pair[1], pair[2] if pair
2448+
if pair
2449+
parent = pair[1]
2450+
current = pair[2]
2451+
else
2452+
parent = nil
2453+
current = nil
2454+
end
2455+
2456+
regexp = "/#{Regexp.escape(parent.to_s)}/\\.\\./|"
2457+
regexp += "(/#{Regexp.escape(current.to_s)}/\\.\\.$)"
2458+
24512459
if pair && ((parent != SELF_REF && parent != PARENT) ||
24522460
(current != SELF_REF && current != PARENT))
2453-
mod ||= normalized_path.gsub!(
2454-
Regexp.new(
2455-
"/#{Regexp.escape(parent.to_s)}/\\.\\./|" +
2456-
"(/#{Regexp.escape(current.to_s)}/\\.\\.$)"
2457-
), SLASH
2458-
)
2461+
mod ||= normalized_path.gsub!(Regexp.new(regexp), SLASH)
24592462
end
24602463

24612464
mod ||= normalized_path.gsub!(RULE_2D, EMPTY_STR)
24622465
# Non-standard, removes prefixed dotted segments from path.
24632466
mod ||= normalized_path.gsub!(RULE_PREFIXED_PARENT, SLASH)
2464-
end until mod.nil?
2467+
break if mod.nil?
2468+
end
24652469

2466-
return normalized_path
2470+
normalized_path
24672471
end
24682472

24692473
##

lib/addressable/version.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# encoding:utf-8
43
#--
54
# Copyright (C) Bob Aman
65
#

spec/addressable/idna_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# coding: utf-8
43
# Copyright (C) Bob Aman
54
#
65
# Licensed under the Apache License, Version 2.0 (the "License");

spec/addressable/net_http_compat_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# coding: utf-8
43
# Copyright (C) Bob Aman
54
#
65
# Licensed under the Apache License, Version 2.0 (the "License");

spec/addressable/security_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# coding: utf-8
43
# Copyright (C) Bob Aman
54
#
65
# Licensed under the Apache License, Version 2.0 (the "License");

spec/addressable/template_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
# coding: utf-8
43
# Copyright (C) Bob Aman
54
#
65
# Licensed under the Apache License, Version 2.0 (the "License");

0 commit comments

Comments
 (0)