From a5bac0804a5819cbe20cb2a08d484662e8d3708f Mon Sep 17 00:00:00 2001 From: Robert Mullenix Date: Fri, 7 Apr 2017 16:11:40 -0700 Subject: [PATCH] Add support for placeholders that begin with a `_` --- index.js | 2 +- test/example.md | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 15949f2..340f1aa 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ // based on code from Brian White @mscdex mariasql library - https://github.com/mscdex/node-mariasql/blob/master/lib/Client.js#L272-L332 // License: https://github.com/mscdex/node-mariasql/blob/master/LICENSE -var RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g, +var RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z_][a-zA-Z0-9_]*)))/g, DQUOTE = 34, SQUOTE = 39, BSLASH = 92; diff --git a/test/example.md b/test/example.md index ca8b689..268778c 100644 --- a/test/example.md +++ b/test/example.md @@ -60,6 +60,15 @@ it should replace ::name style placeholders with `??` placeholders .should.eql([ 'normal placeholder ? and double semicolon ?? test', [ 'test1', 'test2' ] ]); ``` +it should replace :name style placeholders that start with `_` + +```js + var compile = require('..')(); + + query = 'normal placeholder :p1 and underscore-leading placeholder :_p2 test'; + compile(query, {p1: 'test1', _p2: 'test2'}) + .should.eql([ 'normal placeholder ? and underscore-leading placeholder ? test', [ 'test1', 'test2' ] ]); +``` # postgres-style toNumbered conversion