jsoverson / preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
Other
366 stars 80 forks source link

getTestTemplate() can still fail due to empty/newline string #53

Closed brian428 closed 8 years ago

brian428 commented 9 years ago

I'm running into the same problem that was brought up in issue #46, but for an exclude test. I commented on that issue (https://github.com/jsoverson/preprocess/issues/46#issuecomment-81703776) but haven't seen any responses, so maybe no one is getting notified since the issue is closed?

I'm running a project that appears to end up passing a test string containing only a new line. I'm on Windows, so I think this is coming through as "\r\n". I'm not sure if something outside of preprocess.js is passing something it really shouldn't be, or if it's a result of the regex replacement that happens earlier in the script.

Either way, this blows up in getTestTemplate(). I was able to prevent it by adding a line at the top of testPasses() that contains: if( test && test.replace( /[\n\r\s]*/gi, '' ) == '' ) { test = '' }. (Obviously, this is just saying "after replacing all spaces, cr, and lf, if we're left with an empty string, then set test to an empty string").

I don't understand everything going on in preprocess.js well enough to know if this is a truly viable fix, but for now it's what I'm using to stop it from failing.

BendingBender commented 9 years ago

Thank you for your report! I've fixed a similar issue in master. Could you please test the current master if it still fails in your case?

BendingBender commented 9 years ago

@brian428, can you please try out the 3.x.x series of preprocess and report whether you're still having issues?

brian428 commented 9 years ago

Will do! I'll try to replicate the problem I was having and let you know how it goes.