mikrofusion / gulp-obfuscate

gulp plugin to obfuscate your code using gulp-regex-replace
MIT License
367 stars 39 forks source link

Result replace call null or undefined #1

Closed ArrowBaZ closed 10 years ago

ArrowBaZ commented 10 years ago

Hello,

I have an error JS :

[gulp] Starting 'default'...

node_modules\gulp-obfuscate\node_modules\gulp-regex-replace\index.js:137
        result = result.replace(regexReplace, r);
                        ^
TypeError: Array.prototype.indexOf called on null or undefined
    at indexOf (native)
    at String.replace (native)
    at node_modules\gulp-obfuscate\node_modules\gulp-regex-replace\index.js:137:25
    at Array.forEach (native)
    at convertString (node_modules\gulp-obfuscate\node_modules\gulp-regex-replace\index.js:12
1:13)
mikrofusion commented 10 years ago

Hi @ArrowBaZ. It looks like this error is most likely the result of no input stream (file.contents) being passed into gulp-obfuscate. Can you show me how you are starting gulp-obfuscate (maybe paste your gulpfile so I can take a look)?

ArrowBaZ commented 10 years ago

Thanks for helping me,

gulpfile.js

var gulp = require( 'gulp' );
var obfuscate = require( 'gulp-obfuscate' );

gulp.task( 'default', function ()
{
    return gulp.src( 'test.js' )
        .pipe( obfuscate() );
} );

mikrofusion commented 10 years ago

Thanks for the additional information. I tried to reproduce your issue locally with no success.
I am able to get to get the following gulpfile and test.js file to run without error (gulpfile appears to be identical to yours, test.js is not):

gulpfile.coffee

var gulp = require( 'gulp' );
var obfuscate = require( 'gulp-obfuscate' );

gulp.task('default', function() {
  return gulp.src('test.js').pipe(obfuscate());
});

test.js:

function() {
  console.log('test');
}

command line output:

╰─> gulp
[gulp] Using gulpfile ~/programming/gulp-test/gulpfile.js
[gulp] Starting 'default'...
[gulp] Finished 'default' after 6.63 ms

It's possible that there may be an environment difference between your machine and mine causing this. The error being seen is actually coming from gulp-regex-replace which gulp-obfuscate uses to do all the string replacement. I saw that gulp-regex-replace had a few spots where it could be a little more robust and check to ensure the file contents exist before trying to use them. I've fixed this in gulp-regex-replace version 0.2.2 today.

Here are what I think we should do next to get to the bottom of the problem you are seeing: 1) Install gulp-obfuscate version 0.2.5 - I just published this today, it is updated to use gulp-regex-replace 0.2.2 which has extra checking around file.contents.

2) If step 1 doesn't fix the problem, I recommend we try to get a bare bones project running. Can you use the gulpfile and test.js code I pasted above running as a first step? Once we get that running then we should slowly add in your other code until we see if something breaks.

Please let me know what you find and hopefully we can figure out whats going on here.

ArrowBaZ commented 10 years ago

Ok, i try with your file, no problem. I updated everything, but still have the error with my file. I cut my file to get only the beginning, and no problem... So only caracteres that may cause this bug.

I take step by step the file

.indexOf = function

make the error ! :)

Hope this help you !

mikrofusion commented 10 years ago

@ArrowBaZ thanks for the additional information. With the details you provided I was able to isolate root cause of the problem. The code was incorrectly finding a match against the keys in a lookup array which was returning a bad replace string.

I've published gulp-obfuscate 0.2.7 with the fix to this problem.

Thanks again.