null+****@clear*****
null+****@clear*****
2012年 8月 1日 (水) 17:06:50 JST
Yoji SHIDARA 2012-08-01 17:06:50 +0900 (Wed, 01 Aug 2012) New Revision: cab5a32857bf99cd298afadc2b8b6af8e846efd7 https://github.com/groonga/gcs/commit/cab5a32857bf99cd298afadc2b8b6af8e846efd7 Log: Support query including single quotes Modified files: lib/q-translator.js test/q-translator.test.js Modified: lib/q-translator.js (+5 -1) =================================================================== --- lib/q-translator.js 2012-08-01 16:57:12 +0900 (9a495b1) +++ lib/q-translator.js 2012-08-01 17:06:50 +0900 (8c5affb) @@ -28,6 +28,10 @@ function throwTranslateError(query, context, detail) { throw new Error(message); } +function escapeTerm(term) { + return term.replace(/'/, "\\'"); +} + QueryTranslator.prototype = { translateIndividualTerm: function(query, context) { var term = ''; @@ -37,7 +41,7 @@ QueryTranslator.prototype = { } term += query[context.offset]; } - return context.defaultField + ":'" + term + "'"; + return context.defaultField + ":'" + escapeTerm(term) + "'"; }, skipSpaces: function(query, context) { for (; context.offset < query.length; context.offset++) { Modified: test/q-translator.test.js (+4 -0) =================================================================== --- test/q-translator.test.js 2012-08-01 16:57:12 +0900 (21b99e6) +++ test/q-translator.test.js 2012-08-01 17:06:50 +0900 (b316778) @@ -32,4 +32,8 @@ suite('QueryTranslator', function() { "star wars", "field:'star'", "star".length); + testIndividualTerm("an individual term: single quote", + "let's go", + "field:'let\\'s'", + "let's".length); }); -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... 下載