Skip to content

Commit

Permalink
Replacement updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Jun 14, 2012
1 parent 43ba27e commit a569f76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions lib/DAV/plugins/codesearch.js
Expand Up @@ -195,7 +195,7 @@ var prevFile;
// grep has a funny way of handling new lines (that is to say, it's non-existent)
// if we're not doing a regex search, then we must split everything between the
// new lines, escape the content, and then smush it back together; due to
// new lines, this is also why we're now passing -P as default to grep
// new lines, this is also why we're now passing -P as default to grep
if (!Util.isTrue(options.replaceAll) && !Util.isTrue(options.regexp)) {
var splitQuery = query.split("\\n");

Expand All @@ -209,10 +209,17 @@ var prevFile;

cmd += " --exclude=*{" + jsDAV_Codesearch_Plugin.PATTERN_EDIR + "}*"
+ " --include=" + include
+ " '" + query + "'"
+ " '" + query.replace(/-/g, "\\-") + "'"
+ " \"" + Util.escapeShell(node.path) + "\"";

if (Util.isTrue(options.replaceAll) && !Util.empty(options.replacement)) {
if (Util.isTrue(options.replaceAll)) {
if (options.replacement === undefined)
options.replacement = "";

if (!Util.isTrue(options.regexp)) {
query = Util.escapeRegExp(query);
}

// pipe the grep results into perl
cmd += " -l | xargs " + jsDAV_Codesearch_Plugin.PERL_CMD +
// print the grep result to STDOUT (to arrange in parseSearchResult())
Expand Down Expand Up @@ -241,19 +248,15 @@ var prevFile;
this.grep.stdout.on("data", function(data) {
if (!Util.empty(data)) {
buffer += data;
if(data.indexOf("\n") !== -1) {
count += self.parseSearchResult(data, node.path, options, prevFile, cbwrite);
buffer = '';
}
count += self.parseSearchResult(data, node.path, options, prevFile, cbwrite);
buffer = '';
}
});
this.grep.stderr.on("data", function(data) {
if (!Util.empty(data)) {
buffer += data;
if(data.indexOf("\n") !== -1) {
count += self.parseSearchResult(data, node.path, options, prevFile, cbwrite);
buffer = '';
}
count += self.parseSearchResult(data, node.path, options, prevFile, cbwrite);
buffer = '';
}
});
this.grep.on("exit", function(code, signal) {
Expand Down
2 changes: 1 addition & 1 deletion lib/DAV/util.js
Expand Up @@ -250,7 +250,7 @@ exports.escapeRegExp = function(str) {

// taken from http://xregexp.com/
exports.grepEscapeRegExp = function(str) {
return str.replace(/[-[\]{}()*+?.,\\^$|#\s"']/g, "\\$&");
return str.replace(/[[\]{}()*+?.,\\^$|#\s"']/g, "\\$&");
}

exports.escapeShell = function(str) {
Expand Down
2 changes: 1 addition & 1 deletion lib/jsdav.js
Expand Up @@ -7,7 +7,7 @@
*/
"use strict";

exports.debugMode = false;
exports.debugMode = true;

exports.__INODE__ = 1 << 2;
exports.__ICOLLECTION__ = 1 << 3;
Expand Down

0 comments on commit a569f76

Please sign in to comment.