Skip to content
Browse files

Merge pull request #26 from ajaxorg/fix/search_ui

Fix/search ui
  • Loading branch information...
2 parents 360b214 + 30a3ddf commit 7fc5b36a5074668f40aad8b45f82a6fbbec04c88 @javruben javruben committed Jun 19, 2012
Showing with 19 additions and 10 deletions.
  1. +18 −9 lib/DAV/plugins/codesearch.js
  2. +1 −1 lib/DAV/util.js
View
27 lib/DAV/plugins/codesearch.js
@@ -190,12 +190,13 @@ var prevFile;
}
if (Util.isTrue(options.wholeword))
- cmd += " -w"
+ cmd += " -w";
+
var query = options.query;
// 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 +210,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())
@@ -221,9 +229,8 @@ var prevFile;
" if s/" + query + "/" + options.replacement + "/mg" + ( !Util.isTrue(options.casesensitive) ? "i" : "" ) + ";'"
}
- if (jsDAV.debugMode) {
- Util.log("search command: " + cmd);
- }
+ if (jsDAV.debugMode)
+ Util.log("search command: " + cmd);
try {
this.grep = Spawn("/bin/bash", ["-c", cmd]);
@@ -241,7 +248,9 @@ var prevFile;
this.grep.stdout.on("data", function(data) {
if (!Util.empty(data)) {
buffer += data;
- if(data.indexOf("\n") !== -1) {
+ if (data.indexOf("\n") !== -1) {
+ if (jsDAV.debugMode)
+ Util.log(data);
count += self.parseSearchResult(data, node.path, options, prevFile, cbwrite);
buffer = '';
}
@@ -257,7 +266,7 @@ var prevFile;
}
});
this.grep.on("exit", function(code, signal) {
- cbend(null, '\nResults: {"count": '+ count + ', "filecount":' + filecount + '}');
+ cbend(null, '\nResults: {"count": '+ count + ', "filecount":' + filecount + '}\n');
});
};
View
2 lib/DAV/util.js
@@ -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) {

0 comments on commit 7fc5b36

Please sign in to comment.
Something went wrong with that request. Please try again.