Skip to content

Commit c405f6d

Browse files
committed
1. Correct HTTPRequest encoding
2. Make SimpleStore robust on private browsing
1 parent e7351dd commit c405f6d

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/HttpRequest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,14 @@ public String getResponseText() {
221221
if (matcher.find()) {
222222
charset = matcher.group(1);
223223
} else {
224-
responseText = tmp;
224+
matcher = Pattern.compile(
225+
"<meta.*\\s+charset\\s*=\\s*[\'\"]([^'\"]*)\\s*[\'\"].*>",
226+
Pattern.MULTILINE | Pattern.CASE_INSENSITIVE).matcher(tmp);
227+
if (matcher.find()) {
228+
charset = matcher.group(1);
229+
} else {
230+
responseText = tmp;
231+
}
225232
}
226233
}
227234
}
@@ -552,9 +559,11 @@ private void request() {
552559
if (checkAbort()) return; // exception caused by abort action
553560
//e.printStackTrace();
554561
status = connection.getResponseCode();
555-
readyState = 4;
556-
if (onreadystatechange != null) {
557-
onreadystatechange.onLoaded();
562+
if (readyState != 4) {
563+
readyState = 4;
564+
if (onreadystatechange != null) {
565+
onreadystatechange.onLoaded();
566+
}
558567
}
559568
connection = null;
560569
readyState = 0;

sources/net.sf.j2s.ajax/store/net/sf/j2s/store/SimpleStore.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ private SimpleStore() {
2222
isLocalFile = true;
2323
}
2424
if (window["j2s.html5.store"] && window["localStorage"] != null && (ua.indexOf ("gecko/") == -1 || !isLocalFile)) {
25-
this.store = new net.sf.j2s.store.HTML5LocalStorage ();
26-
return;
25+
try {
26+
localStorage.setItem('net.sf.j2s.test', '1');
27+
localStorage.removeItem('net.sf.j2s.test');
28+
this.store = new net.sf.j2s.store.HTML5LocalStorage ();
29+
return;
30+
} catch (error) {
31+
}
2732
}
2833
var isLocal = false;
2934
try {
@@ -41,10 +46,10 @@ private SimpleStore() {
4146
}
4247
*/ {
4348
File storeFile = new File(System.getProperty("user.home"), ".java2script.store");
44-
this.store = new INIFileStore(storeFile.getAbsolutePath());
49+
this.store = new INIFileStore(storeFile.getAbsolutePath());
4550
}
4651
}
47-
52+
4853
public static SimpleStore getDefault() {
4954
if (singleton == null) {
5055
singleton = new SimpleStore();

0 commit comments

Comments
 (0)