<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -179,8 +179,8 @@ module JsChat
   end
 
   module Errors
-    class InvalidName &lt; JsChat::Error
-    end
+    class InvalidName &lt; JsChat::Error ; end
+    class MessageTooLong &lt; JsChat::Error ; end
   end
 
   # User initially has a nil name
@@ -291,7 +291,7 @@ module JsChat
   end
 
   def log(level, message)
-    if Object.const_defined? :ServerConfig
+    if Object.const_defined? :ServerConfig and ServerConfig[:logger]
       if @user
         message = &quot;#{@user.name}: #{message}&quot;
       end
@@ -329,6 +329,11 @@ module JsChat
 
   def receive_data(data)
     response = ''
+
+    if data and data.size &gt; ServerConfig[:max_message_length]
+      raise JsChat::Errors::MessageTooLong.new('Message too long')
+    end
+
     data.strip.split(&quot;\n&quot;).each do |line|
       # Receive the identify request
       input = JSON.parse line 
@@ -356,6 +361,8 @@ module JsChat
     end
 
     response
+  rescue JsChat::Errors::MessageTooLong =&gt; exception
+    send_response exception
   rescue Exception =&gt; exception
     puts &quot;Data that raised exception: #{exception}&quot;
     p data</diff>
      <filename>jschat.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,8 @@ logger = Logger.new(STDOUT)
 ServerConfig = {
   :port =&gt; 6789,
   :ip =&gt; '0.0.0.0',
-  :logger =&gt; logger
+  :logger =&gt; logger,
+  :max_message_length =&gt; 500
 }
 
 EM.run do</diff>
      <filename>server.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,10 @@ require 'eventmachine'
 require 'json'
 require File.join(File.dirname(__FILE__), '../', 'jschat.rb')
 
+ServerConfig = {
+  :max_message_length =&gt; 500
+}
+
 class JsChat::Room
   def self.reset
     @@rooms = nil
@@ -55,26 +59,26 @@ class TestJsChat &lt; Test::Unit::TestCase
   end
 
   def test_ensure_nicks_are_unique
-    @jschat.receive_data({ 'identify' =&gt; 'alex' }.to_json)
+    identify_as 'alex'
 
     # Obvious duplicate
-    result = JSON.parse @jschat.receive_data({ 'identify' =&gt; 'alex' }.to_json)
+    result = identify_as 'alex'
     assert result['error']
 
     # Case
-    result = JSON.parse @jschat.receive_data({ 'identify' =&gt; 'Alex' }.to_json)
+    result = identify_as 'Alex'
     assert result['error']
   end
 
   def test_invalid_room_name
-    @jschat.receive_data({ 'identify' =&gt; 'bob' }.to_json)
+    identify_as 'bob'
     response = JSON.parse @jschat.receive_data({ 'join' =&gt; 'oublinet' }.to_json)
     assert_equal 'Invalid room name', response['error']['message']
   end
 
   def test_join
+    identify_as 'bob'
     expected = { 'display' =&gt; 'join', 'join' =&gt; { 'user' =&gt; 'bob', 'room' =&gt; '#oublinet' } }.to_json + &quot;\n&quot;
-    @jschat.receive_data({ 'identify' =&gt; 'bob' }.to_json)
     assert_equal expected, @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
   end
 
@@ -84,7 +88,7 @@ class TestJsChat &lt; Test::Unit::TestCase
   end
 
   def test_join_more_than_once
-    @jschat.receive_data({ 'identify' =&gt; 'bob' }.to_json)
+    identify_as 'bob'
 
     expected = { 'display' =&gt; 'error', 'error' =&gt; { 'message' =&gt; 'Already in that room' } }.to_json + &quot;\n&quot;
     @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
@@ -92,14 +96,13 @@ class TestJsChat &lt; Test::Unit::TestCase
   end
 
   def test_identify_twice
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
+    identify_as 'nick'
     expected = { 'display' =&gt; 'error', 'error' =&gt; { 'message' =&gt; 'Name already taken' } }.to_json + &quot;\n&quot;
     assert_equal expected, @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
   end
 
   def test_names
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
 
     # Add a user
     @jschat.add_user 'alex', '#oublinet'
@@ -118,72 +121,79 @@ class TestJsChat &lt; Test::Unit::TestCase
   end
 
   def test_message_not_in_room
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
     @jschat.add_user 'alex', '#oublinet'
     response = JSON.parse @jschat.receive_data({ 'send' =&gt; 'hello', 'to' =&gt; '#merk' }.to_json)
     assert_equal 'Please join this room first', response['error']['message']
   end
 
   def test_message
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
     @jschat.add_user 'alex', '#oublinet'
     assert @jschat.receive_data({ 'send' =&gt; 'hello', 'to' =&gt; '#oublinet' }.to_json)
   end
 
   def test_message_ignores_case
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
     @jschat.add_user 'alex', '#oublinet'
     response = @jschat.receive_data({ 'send' =&gt; 'hello', 'to' =&gt; '#Oublinet' }.to_json)
     assert response
   end
 
   def test_part
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
     @jschat.add_user 'alex', '#oublinet'
     response = JSON.parse @jschat.receive_data({ 'part' =&gt; '#oublinet'}.to_json)
     assert_equal '#oublinet', response['part']['room']
   end
 
   def test_private_message
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
+    identify_as 'nick'
     @jschat.add_user 'alex', '#oublinet'
     response = JSON.parse @jschat.receive_data({ 'send' =&gt; 'hello', 'to' =&gt; 'alex' }.to_json)
     assert_equal 'hello', response['message']['message']
   end
 
   def test_private_message_ignores_case
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
+    identify_as 'nick'
     @jschat.add_user 'alex', '#oublinet'
     response = JSON.parse @jschat.receive_data({ 'send' =&gt; 'hello', 'to' =&gt; 'Alex' }.to_json)
     assert_equal 'hello', response['message']['message']
   end
 
   def test_log_request
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
     @jschat.receive_data({ 'send' =&gt; 'hello', 'to' =&gt; '#oublinet' }.to_json)
     response = JSON.parse @jschat.receive_data({ 'lastlog' =&gt; '#oublinet' }.to_json)
     assert_equal 'hello', response['messages'].last['message']['message']
   end
 
   def test_name_change
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
     @jschat.add_user 'alex', '#oublinet'
     response = JSON.parse @jschat.receive_data({ 'change' =&gt; 'user', 'user' =&gt; { 'name' =&gt; 'bob' }}.to_json)
     assert_equal 'notice', response['display']
   end
 
   def test_name_change_duplicate
-    @jschat.receive_data({ 'identify' =&gt; 'nick' }.to_json)
-    @jschat.receive_data({ 'join' =&gt; '#oublinet' }.to_json)
+    identify_as 'nick', '#oublinet'
     @jschat.add_user 'alex', '#oublinet'
     response = JSON.parse @jschat.receive_data({ 'change' =&gt; 'user', 'user' =&gt; { 'name' =&gt; 'alex' }}.to_json)
     assert_equal 'error', response['display']
   end
+
+  def test_max_message_length
+    identify_as 'nick', '#oublinet'
+    response = JSON.parse @jschat.receive_data({ 'send' =&gt; 'a' * 1000, 'to' =&gt; '#oublinet' }.to_json)
+    assert response['error']
+  end
+
+  private
+
+    def identify_as(name, channel = nil)
+      result = @jschat.receive_data({ 'identify' =&gt; name }.to_json)
+      result = @jschat.receive_data({ 'join' =&gt; channel }.to_json) if channel
+      result
+    end
 end
 </diff>
      <filename>test/server_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>854379068e54f9dfaca9c3eb541de19fe13205d6</id>
    </parent>
  </parents>
  <author>
    <name>Alex Young</name>
    <email>alex@helicoid.net</email>
  </author>
  <url>http://github.com/alexyoung/jschat/commit/5cbdd05396afeb6e1ad0bb06eb083ed0ab18f744</url>
  <id>5cbdd05396afeb6e1ad0bb06eb083ed0ab18f744</id>
  <committed-date>2009-05-11T03:21:31-07:00</committed-date>
  <authored-date>2009-05-11T03:21:31-07:00</authored-date>
  <message>Maximum message length now detected and an error is raised.  Closes #40.</message>
  <tree>953d42ee27bf82ffa7e39b67f8ad13e8078ede10</tree>
  <committer>
    <name>Alex Young</name>
    <email>alex@helicoid.net</email>
  </committer>
</commit>
