Skip to content

Commit

Permalink
Formatting change: {...} should have spaces inside the braces
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Jun 11, 2019
1 parent 242f007 commit a8c8478
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ then the `permessage-deflate` extension will receive the call:

```rb
ext.create_server_session([
{'server_no_context_takeover' => true, 'server_max_window_bits' => 8},
{'server_max_window_bits' => 15}
{ 'server_no_context_takeover' => true, 'server_max_window_bits' => 8 },
{ 'server_max_window_bits' => 15 }
])
```

Expand All @@ -244,8 +244,8 @@ implement the following methods, as well as the *Session* API listed below.
```rb
client_session.generate_offer
# e.g. -> [
# {'server_no_context_takeover' => true, 'server_max_window_bits' => 8},
# {'server_max_window_bits' => 15}
# { 'server_no_context_takeover' => true, 'server_max_window_bits' => 8 },
# { 'server_max_window_bits' => 15 }
# ]
```

Expand All @@ -270,7 +270,7 @@ must implement the following methods, as well as the *Session* API listed below.

```rb
server_session.generate_response
# e.g. -> {'server_max_window_bits' => 8}
# e.g. -> { 'server_max_window_bits' => 8 }
```

This returns the set of parameters the server session wants to send in its
Expand Down
12 changes: 6 additions & 6 deletions lib/websocket/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def add(ext)
end

if @by_name.has_key?(ext.name)
raise TypeError, %Q{An extension with name "#{ext.name}" is already registered}
raise TypeError, %Q{An extension with name "#{ ext.name }" is already registered}
end

@by_name[ext.name] = ext
Expand Down Expand Up @@ -78,18 +78,18 @@ def activate(header)

responses.each_offer do |name, params|
unless record = @index[name]
raise ExtensionError, %Q{Server sent am extension response for unknown extension "#{name}"}
raise ExtensionError, %Q{Server sent am extension response for unknown extension "#{ name } }
end

ext, session = *record

if reserved = reserved?(ext)
raise ExtensionError, %Q{Server sent two extension responses that use the RSV#{reserved[0]} } +
%Q{ bit: "#{reserved[1]}" and "#{ext.name}"}
raise ExtensionError, %Q{Server sent two extension responses that use the RSV#{ reserved[0] }} +
%Q{bit: "#{ reserved[1] }" and "#{ ext.name }"}
end

unless session.activate(params) == true
raise ExtensionError, %Q{Server send unacceptable extension parameters: #{Parser.serialize_params(name, params)}}
raise ExtensionError, %Q{Server send unacceptable extension parameters: #{ Parser.serialize_params(name, params) }}
end

reserve(ext)
Expand Down Expand Up @@ -118,7 +118,7 @@ def generate_response(header)
end

def valid_frame_rsv(frame)
allowed = {:rsv1 => false, :rsv2 => false, :rsv3 => false}
allowed = { :rsv1 => false, :rsv2 => false, :rsv3 => false }

if MESSAGE_OPCODES.include?(frame.opcode)
@sessions.each do |ext, session|
Expand Down
8 changes: 4 additions & 4 deletions lib/websocket/extensions/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Parser
TOKEN = /([!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+)/
NOTOKEN = /([^!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z])/
QUOTED = /"((?:\\[\x00-\x7f]|[^\x00-\x08\x0a-\x1f\x7f"])*)"/
PARAM = %r{#{TOKEN.source}(?:=(?:#{TOKEN.source}|#{QUOTED.source}))?}
EXT = %r{#{TOKEN.source}(?: *; *#{PARAM.source})*}
EXT_LIST = %r{^#{EXT.source}(?: *, *#{EXT.source})*$}
PARAM = %r{#{ TOKEN.source }(?:=(?:#{ TOKEN.source }|#{ QUOTED.source }))?}
EXT = %r{#{ TOKEN.source }(?: *; *#{ PARAM.source })*}
EXT_LIST = %r{^#{ EXT.source }(?: *, *#{ EXT.source })*$}
NUMBER = /^-?(0|[1-9][0-9]*)(\.[0-9]+)?$/

ParseError = Class.new(ArgumentError)
Expand All @@ -19,7 +19,7 @@ def self.parse_header(header)
return offers if header == '' or header.nil?

unless header =~ EXT_LIST
raise ParseError, "Invalid Sec-WebSocket-Extensions header: #{header}"
raise ParseError, "Invalid Sec-WebSocket-Extensions header: #{ header }"
end

scanner = StringScanner.new(header)
Expand Down
28 changes: 14 additions & 14 deletions spec/websocket/extensions/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,60 @@ def parse(string)

it "parses one offer with no params" do
expect(parse 'a').to eq [
{:name => "a", :params => {}}
{ :name => "a", :params => {} }
]
end

it "parses two offers with no params" do
expect(parse 'a, b').to eq [
{:name => "a", :params => {}}, {:name => "b", :params => {}}
{ :name => "a", :params => {} }, { :name => "b", :params => {} }
]
end

it "parses a duplicate offer name" do
expect(parse 'a, a').to eq [
{:name => "a", :params => {}},
{:name => "a", :params => {}}
{ :name => "a", :params => {} },
{ :name => "a", :params => {} }
]
end

it "parses a flag" do
expect(parse 'a; b').to eq [
{:name => "a", :params => {"b" => true}}
{ :name => "a", :params => { "b" => true } }
]
end

it "parses an unquoted param" do
expect(parse 'a; b=1').to eq [
{:name => "a", :params => {"b" => 1}}
{ :name => "a", :params => { "b" => 1 } }
]
end

it "parses a quoted param" do
expect(parse 'a; b="hi, \"there"').to eq [
{:name => "a", :params => {"b" => 'hi, "there'}}
{ :name => "a", :params => { "b" => 'hi, "there' } }
]
end

it "parses multiple params" do
expect(parse 'a; b; c=1; d="hi"').to eq [
{:name => "a", :params => {"b" => true, "c" => 1, "d" => "hi"}}
{ :name => "a", :params => { "b" => true, "c" => 1, "d" => "hi" } }
]
end

it "parses duplicate params" do
expect(parse 'a; b; c=1; b="hi"').to eq [
{:name => "a", :params => {"b" => [true, "hi"], "c" => 1}}
{ :name => "a", :params => { "b" => [true, "hi"], "c" => 1 } }
]
end

it "parses multiple complex offers" do
expect(parse 'a; b=1, c, b; d, c; e="hi, there"; e, a; b').to eq [
{:name => "a", :params => {"b" => 1}},
{:name => "c", :params => {}},
{:name => "b", :params => {"d" => true}},
{:name => "c", :params => {"e" => ['hi, there', true]}},
{:name => "a", :params => {"b" => true}}
{ :name => "a", :params => { "b" => 1 } },
{ :name => "c", :params => {} },
{ :name => "b", :params => { "d" => true } },
{ :name => "c", :params => { "e" => ['hi, there', true] } },
{ :name => "a", :params => { "b" => true } }
]
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/websocket/extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

describe "client sessions" do
before do
@offer = {"mode" => "compress"}
@offer = { "mode" => "compress" }
allow(@ext).to receive(:create_client_session).and_return(@session)
allow(@session).to receive(:generate_offer).and_return(@offer)
@extensions.add(@ext)
Expand Down Expand Up @@ -248,7 +248,7 @@

describe "server sessions" do
before do
@response = {"mode" => "compress"}
@response = { "mode" => "compress" }
allow(@ext).to receive(:create_server_session).and_return(@session)
allow(@session).to receive(:generate_response).and_return(@response)

Expand All @@ -269,12 +269,12 @@

describe :generate_response do
it "asks the extension for a server session with the offer" do
expect(@ext).to receive(:create_server_session).with([{"flag" => true}]).exactly(1).and_return(@session)
expect(@ext).to receive(:create_server_session).with([{ "flag" => true }]).exactly(1).and_return(@session)
@extensions.generate_response("deflate; flag")
end

it "asks the extension for a server session with multiple offers" do
expect(@ext).to receive(:create_server_session).with([{"a" => true}, {"b" => true}]).exactly(1).and_return(@session)
expect(@ext).to receive(:create_server_session).with([{ "a" => true }, { "b" => true }]).exactly(1).and_return(@session)
@extensions.generate_response("deflate; a, deflate; b")
end

Expand Down

0 comments on commit a8c8478

Please sign in to comment.