Skip to content

Commit

Permalink
Fix isJson in secure-ajax with data URIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tapina committed Feb 14, 2018
1 parent 9f95186 commit 9a1d9b2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/helpers/secure-ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
if (request.readyState === 4) {
const reqText = (request.responseText || '');
// TODO FIX/DELETE this is just horrible, migrated from helpers.js hacking string prototype
const isJson = (/^[\],:{}\s]*$/.test(reqText.replace(/\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
const isJson = t => (/^[\],:{}\s]*$/.test(t.replace(/\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/g, ']')
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')));

Expand All @@ -64,7 +64,7 @@
// just about to resolve the request
ajax.onloadend();
resolve(request.response);
} else if (settings.dataType === 'json' && isJson) {
} else if (settings.dataType === 'json' && isJson(reqText)) {
// just about to resolve the request
ajax.onloadend();
resolve(JSON.parse(reqText));
Expand All @@ -83,7 +83,7 @@
if (parsedDataUri) {
// just about to resolve the request
ajax.onloadend();
resolve(settings.dataType === 'json' && parsedDataUri.isJson() ? JSON.parse(parsedDataUri) : parsedDataUri);
resolve(settings.dataType === 'json' && isJson(parsedDataUri) ? JSON.parse(parsedDataUri) : parsedDataUri);
return;
}
}
Expand Down

0 comments on commit 9a1d9b2

Please sign in to comment.