From cffe3247ef884529a5b8080f13d09ca892a64662 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 23 Mar 2024 21:56:40 -0400 Subject: [PATCH 1/2] test: update uri tests with better names so we can clearly tell which entry fails --- test/test_http_cookie.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index aeb3710..0926cb9 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -1016,7 +1016,7 @@ def test_valid_for_uri? 'https://www.example.com/dir2/test.html', ] }, - HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2/', + HTTP::Cookie.parse('a3=b; domain=example.com; path=/dir2/', URI('http://example.com/dir/file.html')).first => { true => [ 'https://example.com/dir2/test.html', @@ -1044,7 +1044,7 @@ def test_valid_for_uri? 'file:///dir2/test.html', ] }, - HTTP::Cookie.parse('a4=b; secure', + HTTP::Cookie.parse('a5=b; secure', URI('https://example.com/dir/file.html')).first => { true => [ 'https://example.com/dir/test.html', @@ -1056,7 +1056,7 @@ def test_valid_for_uri? 'file:///dir2/test.html', ] }, - HTTP::Cookie.parse('a5=b', + HTTP::Cookie.parse('a6=b', URI('https://example.com/')).first => { true => [ 'https://example.com', @@ -1065,7 +1065,7 @@ def test_valid_for_uri? 'file:///', ] }, - HTTP::Cookie.parse('a6=b; path=/dir', + HTTP::Cookie.parse('a7=b; path=/dir', 'http://example.com/dir/file.html').first => { true => [ 'http://example.com/dir', From 22ea7af08639ca7792b238a0c6a08c2083a62b12 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 24 Mar 2024 09:15:25 -0400 Subject: [PATCH 2/2] fix: be explicit about frozen string literals to quash warnings --- lib/http/cookie.rb | 5 +++-- lib/http/cookie/scanner.rb | 7 ++++--- test/helper.rb | 2 +- test/test_http_cookie.rb | 3 ++- test/test_http_cookie_jar.rb | 1 + 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/http/cookie.rb b/lib/http/cookie.rb index e6d4d32..431d926 100644 --- a/lib/http/cookie.rb +++ b/lib/http/cookie.rb @@ -1,4 +1,5 @@ # :markup: markdown +# frozen_string_literal: true require 'http/cookie/version' require 'http/cookie/uri_parser' require 'time' @@ -425,7 +426,7 @@ def domain= domain # Returns the domain, with a dot prefixed only if the domain flag is # on. def dot_domain - @for_domain ? '.' << @domain : @domain + @for_domain ? (+'.') << @domain : @domain end # Returns the domain attribute value as a DomainName object. @@ -595,7 +596,7 @@ def valid_for_uri?(uri) # Returns a string for use in the Cookie header, i.e. `name=value` # or `name="value"`. def cookie_value - "#{@name}=#{Scanner.quote(@value)}" + +"#{@name}=#{Scanner.quote(@value)}" end alias to_s cookie_value diff --git a/lib/http/cookie/scanner.rb b/lib/http/cookie/scanner.rb index 8dbd086..70240b1 100644 --- a/lib/http/cookie/scanner.rb +++ b/lib/http/cookie/scanner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'http/cookie' require 'strscan' require 'time' @@ -23,7 +24,7 @@ def initialize(string, logger = nil) class << self def quote(s) return s unless s.match(RE_BAD_CHAR) - '"' << s.gsub(/([\\"])/, "\\\\\\1") << '"' + (+'"') << s.gsub(/([\\"])/, "\\\\\\1") << '"' end end @@ -32,7 +33,7 @@ def skip_wsp end def scan_dquoted - ''.tap { |s| + (+'').tap { |s| case when skip(/"/) break @@ -51,7 +52,7 @@ def scan_name end def scan_value(comma_as_separator = false) - ''.tap { |s| + (+'').tap { |s| case when scan(/[^,;"]+/) s << matched diff --git a/test/helper.rb b/test/helper.rb index 1e1a514..c03c0cc 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -7,7 +7,7 @@ module Test module Unit module Assertions def assert_warn(pattern, message = nil, &block) - class << (output = "") + class << (output = +"") alias write << end stderr, $stderr = $stderr, output diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index 0926cb9..6f8ce87 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# frozen_string_literal: false require File.expand_path('helper', File.dirname(__FILE__)) require 'psych' if !defined?(YAML) && RUBY_VERSION == "1.9.2" require 'yaml' @@ -757,7 +758,7 @@ def test_max_age= assert_equal 12, cookie.max_age cookie.max_age = -3 - assert_equal -3, cookie.max_age + assert_equal(-3, cookie.max_age) end def test_session diff --git a/test/test_http_cookie_jar.rb b/test/test_http_cookie_jar.rb index e59c018..b1f9eda 100644 --- a/test/test_http_cookie_jar.rb +++ b/test/test_http_cookie_jar.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require File.expand_path('helper', File.dirname(__FILE__)) require 'tmpdir'