Skip to content

Commit

Permalink
Insert a BOM check for import and file upload
Browse files Browse the repository at this point in the history
* Similar to @janekptacijarabaci fix in greasemonkey/greasemonkey#1940
* Fix compliance with STYLEGUIDE.md and usage of pre-initialized identifiers
* Currently **do not** propagate BOM with meta routine or user.js source with and without installation count increment
* BOM currently shows up in Ace as a exclamation triangle with "This character may get silently deleted by one or more browsers"

**NOTE**: Many thanks to the report by @cvzi and applies to OpenUserJS#200 and partially outlined in OpenUserJS#198.
  • Loading branch information
Martii committed Sep 10, 2014
1 parent 454562f commit c496baf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions controllers/scriptStorage.js
Expand Up @@ -227,11 +227,12 @@ exports.getMeta = function (aChunks, aCallback) {
var str = '';
var i = 0;
var len = aChunks.length;
var header = null;

for (; i < aChunks.length; ++i) {
var header = null;
header = null;
str += aChunks[i];
header = /^\/\/ ==UserScript==([\s\S]*?)^\/\/ ==\/UserScript==/m.exec(str);
header = /^(?:\uFEFF)?\/\/ ==UserScript==([\s\S]*?)^\/\/ ==\/UserScript==/m.exec(str);

if (header && header[1]) { return aCallback(parseMeta(header[1], true)); }
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/user.js
Expand Up @@ -925,7 +925,7 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {

if (options.javascriptBlob.isUserJS) {
//
var userscriptHeaderRegex = /^\/\/ ==UserScript==([\s\S]*?)^\/\/ ==\/UserScript==/m;
var userscriptHeaderRegex = /^(?:\uFEFF)?\/\/ ==UserScript==([\s\S]*?)^\/\/ ==\/UserScript==/m;
var m = userscriptHeaderRegex.exec(aBlobUtf8);
if (m && m[1]) {
var userscriptMeta = scriptStorage.parseMeta(m[1], true);
Expand Down

1 comment on commit c496baf

@Martii
Copy link
Owner

@Martii Martii commented on c496baf Sep 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back ref: OpenUserJS#348

Please sign in to comment.