Permalink
Browse files

Replacement updates

  • Loading branch information...
1 parent 43ba27e commit a569f76cd9f63a0b5bde760fc7594ef06873db91 @gjtorikian gjtorikian committed Jun 14, 2012
Showing with 16 additions and 13 deletions.
  1. +14 −11 lib/DAV/plugins/codesearch.js
  2. +1 −1 lib/DAV/util.js
  3. +1 −1 lib/jsdav.js
@@ -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");
@@ -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())
@@ -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) {
View
@@ -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) {
View
@@ -7,7 +7,7 @@
*/
"use strict";
-exports.debugMode = false;
+exports.debugMode = true;
exports.__INODE__ = 1 << 2;
exports.__ICOLLECTION__ = 1 << 3;

0 comments on commit a569f76

Please sign in to comment.