Skip to content

Get tests passing with frozen-string-literals enabled. #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

source 'http://rubygems.org'

group :development do
gem 'rake'
gem 'rspec', '~> 3.0'
gem 'rspec', '~> 3.7'

# Use same version as Code Climate for consistency with CI
# https://github.com/codeclimate/codeclimate-rubocop/blob/master/Gemfile.lock
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# WebSocket protocol implementation in Ruby
# This module does not provide a WebSocket server or client, but is made for using
# in http servers or clients to provide WebSocket support.
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
class Error < RuntimeError
class Frame < ::WebSocket::Error
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/exception_handler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module ExceptionHandler
attr_accessor :error
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
autoload :Base, "#{::WebSocket::ROOT}/websocket/frame/base"
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
# @abstract Subclass and override to implement custom frames
Expand Down
4 changes: 3 additions & 1 deletion lib/websocket/frame/data.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
class Data < String
Expand All @@ -11,7 +13,7 @@ def <<(*args)

# Convert all arguments to ASCII-8BIT for easier traversing
def convert_args(args)
args.each { |arg| arg.force_encoding('ASCII-8BIT') }
args.collect { |arg| arg.dup.force_encoding('ASCII-8BIT') }
end

# Extract mask from 4 first bytes according to spec
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/handler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/handler/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
module Handler
Expand Down
7 changes: 4 additions & 3 deletions lib/websocket/frame/handler/handler03.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'securerandom'

Expand Down Expand Up @@ -89,14 +90,14 @@ def opcode_to_type(opcode)
def encode_header
mask = @frame.outgoing_masking? ? 0b10000000 : 0b00000000

output = ''
output = String.new('')
output << (type_to_opcode(@frame.type) | (fin ? 0b10000000 : 0b00000000)) # since more, rsv1-3 are 0 and 0x80 for Draft 4
output << encode_payload_length(@frame.data.size, mask)
output
end

def encode_payload_length(length, mask)
output = ''
output = String.new('')
if length <= 125
output << (length | mask) # since rsv4 is 0
elsif length < 65_536 # write 2 byte length
Expand Down Expand Up @@ -197,7 +198,7 @@ def decode_payload(payload_length, mask)
end

def decode_continuation_frame(application_data, frame_type)
@application_data_buffer ||= ''
@application_data_buffer ||= String.new('')
@application_data_buffer << application_data
@frame_type ||= frame_type
end
Expand Down
1 change: 1 addition & 0 deletions lib/websocket/frame/handler/handler04.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

module WebSocket
module Frame
Expand Down
1 change: 1 addition & 0 deletions lib/websocket/frame/handler/handler05.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

module WebSocket
module Frame
Expand Down
1 change: 1 addition & 0 deletions lib/websocket/frame/handler/handler07.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

module WebSocket
module Frame
Expand Down
1 change: 1 addition & 0 deletions lib/websocket/frame/handler/handler75.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

module WebSocket
module Frame
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/incoming.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
# Construct or parse incoming WebSocket Frame.
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/incoming/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
class Incoming
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/incoming/server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
class Incoming
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/outgoing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
# Construct or parse incoming WebSocket Frame.
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/outgoing/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
class Outgoing
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/frame/outgoing/server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Frame
class Outgoing
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
autoload :Base, "#{::WebSocket::ROOT}/websocket/handshake/base"
Expand Down
6 changes: 4 additions & 2 deletions lib/websocket/handshake/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
# @abstract Subclass and override to implement custom handshakes
Expand All @@ -16,7 +18,7 @@ def initialize(args = {})
@state = :new
@handler = nil

@data = ''
@data = String.new('')
@headers ||= {}
@protocols ||= []
end
Expand Down Expand Up @@ -62,7 +64,7 @@ def leftovers
# @example
# @handshake.uri #=> "ws://example.com/path?query=true"
def uri
uri = secure ? 'wss://' : 'ws://'
uri = String.new(secure ? 'wss://' : 'ws://')
uri << host
uri << ":#{port}" if port
uri << path
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'uri'

module WebSocket
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/client01.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/md5'

module WebSocket
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/client04.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/sha1'
require 'base64'

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

module WebSocket
module Handshake
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/client75.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/client76.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/md5'

module WebSocket
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/server04.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/sha1'
require 'base64'

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

module WebSocket
module Handshake
module Handler
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/handler/server76.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/md5'

module WebSocket
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/handshake/server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module Handshake
# Construct or parse a server WebSocket handshake.
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/nice_inspect.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
module NiceInspect
# Recreate inspect as #to_s will be overwritten
Expand Down
2 changes: 2 additions & 0 deletions lib/websocket/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebSocket
VERSION = '1.2.5'.freeze
end
1 change: 1 addition & 0 deletions spec/frame/incoming_03_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/incoming_04_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/incoming_05_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/incoming_07_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/incoming_75_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/incoming_common_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/masking_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/outgoing_03_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/outgoing_04_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/outgoing_05_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/outgoing_07_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/outgoing_75_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

Expand Down
1 change: 1 addition & 0 deletions spec/frame/outgoing_common_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

require 'spec_helper'

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

require 'spec_helper'

RSpec.describe 'Client draft 4 handshake' do
Expand Down
2 changes: 2 additions & 0 deletions spec/handshake/client_11_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Client draft 11 handshake' do
Expand Down
2 changes: 2 additions & 0 deletions spec/handshake/client_75_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Client draft 75 handshake' do
Expand Down
2 changes: 2 additions & 0 deletions spec/handshake/client_76_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Client draft 76 handshake' do
Expand Down
Loading