[Pkg-javascript-commits] [sockjs-client] 210/434: Better tests for utf encoding

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 57cc1c57c1bd033378430f3b8d511ffe495b1d15
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Fri Nov 25 16:28:42 2011 +0000

    Better tests for utf encoding
    
    No need to send 64K of data, we can limit ourselves to characters that are actually broken.
---
 tests/html/src/tests.coffee | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 23bfe80..d481555 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -25,8 +25,10 @@ echo_factory_factory = (protocol, messages) ->
             if e.data != x
                 for i in [0...e.data.length]
                     if e.data.charCodeAt(i) != x.charCodeAt(i)
-                        #console.log('source: ' + x.charCodeAt(i) + ' differs from: ' + e.data.charCodeAt(i))
-                        true
+                        xx1 = ('0000' + x.charCodeAt(i).toString(16)).slice(-4)
+                        xx2 = ('0000' + e.data.charCodeAt(i).toString(16)).slice(-4)
+                        console.log('source: \\u' + xx1 + ' differs from: \\u' + xx2)
+                        break
             equal(e.data, '' + a[0])
             a.shift()
             if typeof a[0] is 'undefined'
@@ -206,21 +208,29 @@ factor_batch_large_amp = (protocol) ->
     return batch_factory_factory_amp(protocol, messages)
 
 
-factor_echo_utf_encoding = (protocol) ->
-    message = for i in [0..65535] by 64
-                if i is 0x340 # chromium during xhr converts \u0340 to \u0300
-                    continue
-                if i is 0x2000  # again, chrome xhr
-                    continue
-                # ignore surrogates
-                # http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
-                if i >= 0xD800 and i <= 0xDFFF
-                    continue
-                if i >= 62100 and i <= 65472 # again, chrome
-                    continue
-                String.fromCharCode(i)
+
+escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u [...]
+
+generate_killer_string = (escapable) ->
+    s = []
+    c = for i in [0..65535]
+            String.fromCharCode(i)
+    escapable.lastIndex = 0;
+    c.join('').replace escapable,  (a) ->
+            s.push(a)
+            return ''
+    return s.join('')
+
+factor_echo_utf_encoding_simple = (protocol) ->
+    message = for i in [0..256]
+                  String.fromCharCode(i)
     return echo_factory_factory(protocol, [message.join('')])
 
+factor_echo_utf_encoding = (protocol) ->
+        message = generate_killer_string(escapable)
+        return echo_factory_factory(protocol, [message])
+
+
 
 factor_user_close = (protocol) ->
     return ->
@@ -321,7 +331,10 @@ test_protocol_messages = (protocol) ->
         asyncTest("echo1", factor_echo_basic(protocol))
         asyncTest("echo2", factor_echo_rich(protocol))
         asyncTest("unicode", factor_echo_unicode(protocol))
-        asyncTest("utf encoding", factor_echo_utf_encoding(protocol))
+        asyncTest("utf encoding 0x00-0xFF",
+            factor_echo_utf_encoding_simple(protocol))
+        asyncTest("utf encoding killer message",
+            factor_echo_utf_encoding(protocol))
         asyncTest("special_chars", factor_echo_special_chars(protocol))
         asyncTest("large message (ping-pong)",
             factor_echo_large_message(protocol))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list