Skip to content

Commit 66d416f

Browse files
author
Jeremy Williams
committedJun 17, 2011
fix IllegalArgumentException in _randomKey
1 parent 70ffe0d commit 66d416f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed
 

‎src/com/strumsoft/phonegap/websocket/WebSocket.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,15 @@ public void onOpen() {
347347
Log.v("websocket", "Connected!");
348348
appView.post(new Runnable() {
349349
public void run() {
350-
appView.loadUrl(buildJavaScriptData(EVENT_ON_MESSAGE, BLANK_MESSAGE));
350+
appView.loadUrl(buildJavaScriptData(EVENT_ON_OPEN, BLANK_MESSAGE));
351351
}
352352
});
353353
}
354354

355355
public void onClose() {
356356
appView.post(new Runnable() {
357357
public void run() {
358-
appView.loadUrl(buildJavaScriptData(EVENT_ON_MESSAGE, BLANK_MESSAGE));
358+
appView.loadUrl(buildJavaScriptData(EVENT_ON_CLOSE, BLANK_MESSAGE));
359359
}
360360
});
361361
}
@@ -366,7 +366,7 @@ public void onError(Throwable t) {
366366
t.printStackTrace();
367367
appView.post(new Runnable() {
368368
public void run() {
369-
appView.loadUrl(buildJavaScriptData(EVENT_ON_MESSAGE, msg));
369+
appView.loadUrl(buildJavaScriptData(EVENT_ON_ERROR, msg));
370370
}
371371
});
372372
}
@@ -692,8 +692,13 @@ private String _randomKey() {
692692
key = new StringBuilder(key).insert(position, randChar).toString();
693693
}
694694
for (int i = 0; i < spaces; i++) {
695-
int position = r.nextInt(key.length() - 1) + 1;
696-
position = Math.abs(position);
695+
int n = key.length() - 1;
696+
int position;
697+
if(n == 0) {
698+
position = 1;
699+
} else {
700+
position = r.nextInt(n) + 1;
701+
}
697702
key = new StringBuilder(key).insert(position, "\u0020").toString();
698703
}
699704
return key;

0 commit comments

Comments
 (0)
Failed to load comments.