diff --git a/doc/notes.txt b/doc/notes.txt index a7205bf5..af6b0df9 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -155,6 +155,7 @@ TODO: - allow text/binary change - importing from subtree commits to root anyway - publishing Markdown file loads default file? + - better text/binary detection (e.g. 0xa9 copyright) - keyboard shortcuts - ctrl+alt+l on ubuntu locks screen - alt-D doesn't work anymore diff --git a/src/common/util.ts b/src/common/util.ts index a95b35ce..ec27d6a5 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -339,12 +339,10 @@ export function isProbablyBinary(path:string, data?:number[] | Uint8Array) : boo if ((c & 0xe0) == 0xc0) nextra = 1; else if ((c & 0xf0) == 0xe0) nextra = 2; else if ((c & 0xf8) == 0xf0) nextra = 3; - else { - score++; - break; - } + else if (c < 0xa0) score++; + else if (c == 0xff) score++; while (nextra--) { - if ((data[i++] & 0xc0) != 0x80) { + if (i >= data.length || (data[i++] & 0xc0) != 0x80) { score++; break; } diff --git a/src/ide/ui.ts b/src/ide/ui.ts index f467fa13..ef5fa49b 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -88,7 +88,10 @@ function gaEvent(category:string, action:string, label?:string, value?:string) { function alertError(s:string) { gaEvent('error', platform_id||'error', s); setWaitDialog(false); - bootbox.alert(s); + bootbox.alert({ + title: ' Alert', + message: s + }); } function alertInfo(s:string) { setWaitDialog(false); @@ -129,11 +132,11 @@ function requestPersistPermission(interactive: boolean, failureonly: boolean) { if (persistent) { interactive && !failureonly && alertInfo("Your browser says it will persist your local file edits, but you may want to back up your work anyway."); } else { - interactive && alertInfo("Your browser refused to expand the peristent storage quota. Your edits may not be preserved after closing the page."); + interactive && alertError("Your browser refused to expand the peristent storage quota. Your edits may not be preserved after closing the page."); } }); } else { - interactive && alertInfo("Your browser doesn't support expanding the persistent storage quota. Your edits may not be preserved after closing the page."); + interactive && alertError("Your browser doesn't support expanding the persistent storage quota. Your edits may not be preserved after closing the page."); } } diff --git a/test/cli/testutil.js b/test/cli/testutil.js index ba254aa5..734657b2 100644 --- a/test/cli/testutil.js +++ b/test/cli/testutil.js @@ -121,5 +121,10 @@ describe('string functions', function() { assert.ok(util.isProbablyBinary('test.chr')); assert.ok(!util.isProbablyBinary('test.txt')); assert.ok(util.isProbablyBinary('test.dat')); + assert.ok(!util.isProbablyBinary(null, [0x20,0xa9,0x20,0x31,0x39,0x38,0x32])); + assert.ok(util.isProbablyBinary(null, [0x00,0x00])); // 00 is binary + assert.ok(util.isProbablyBinary(null, [0x9f])); // 9f is binary + assert.ok(util.isProbablyBinary(null, [0xff])); // FF is binary + assert.ok(util.isProbablyBinary(null, [0xf0,0x12])); // ran out of data }); });