Skip to content

Commit

Permalink
Revert to pre StringDecoder
Browse files Browse the repository at this point in the history
* A lot of stuff not working with this... not sure this is the correct route.
* Still reading a bit and reverting to keep dev from blocking something

Applies to OpenUserJS#678
  • Loading branch information
Martii committed Oct 6, 2015
1 parent 5bc7884 commit 0bdb009
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,48 +331,40 @@ exports.getMeta = function (aChunks, aCallback) {
// parse the blocks. But strings are memory inefficient compared
// to buffers so we only convert the least number of chunks to
// get the metadata blocks.
var i = 0;
var str = '';
var parser = null;
var rHeaderContent = null;
var headerContent = null;
var hasUserScriptHeaderContent = false;
var blocksContent = {};
var blocks = {};

// Define a local instance of this since it is node native
var StringDecoder = require('string_decoder').StringDecoder;
for (; i < aChunks.length; ++i) {
str += aChunks[i];

// Always enforce UTF-8
var decoder = new StringDecoder('utf8');

var str = decoder.write(aChunks); // NOTE: Watchpoint

if (isDbg) {
console.log('>> decoded str');
console.log(str);
}
for (parser in parsers) {
rHeaderContent = new RegExp(
'^(?:\\uFEFF)?\/\/ ==' + parser + '==([\\s\\S]*?)^\/\/ ==\/'+ parser + '==', 'm'
);
headerContent = rHeaderContent.exec(str);
if (headerContent && headerContent[1]) {
if (parser === 'UserScript') {
hasUserScriptHeaderContent = true;
}

for (parser in parsers) {
rHeaderContent = new RegExp(
'^(?:\\uFEFF)?\/\/ ==' + parser + '==([\\s\\S]*?)^\/\/ ==\/'+ parser + '==', 'm'
);
headerContent = rHeaderContent.exec(str);
if (headerContent && headerContent[1]) {
if (parser === 'UserScript') {
hasUserScriptHeaderContent = true;
blocksContent[parser] = headerContent[1];
}

blocksContent[parser] = headerContent[1];
}
}

if (hasUserScriptHeaderContent) {
for (parser in parsers) {
if (blocksContent[parser]) {
blocks[parser] = parseMeta(parsers[parser], blocksContent[parser]);
if (hasUserScriptHeaderContent) {
for (parser in parsers) {
if (blocksContent[parser]) {
blocks[parser] = parseMeta(parsers[parser], blocksContent[parser]);
}
}
return aCallback(blocks);
}

return aCallback(blocks);
}

aCallback(null);
Expand Down

0 comments on commit 0bdb009

Please sign in to comment.