[Pkg-javascript-commits] [dojo] 78/149: refs #18207, allow escaping $ in string.substitute arguments, useful for specifying queryExpr: '*-bash*' inside a template without having to modify the caller or widget
David Prévot
taffit at moszumanska.debian.org
Sat Feb 27 03:13:49 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository dojo.
commit 1209d791b7a351d83e6187dac373f671ef1ef080
Author: Joerg Sonnenberger <joerg at bec.de>
Date: Fri Sep 11 13:32:20 2015 -0700
refs #18207, allow escaping $ in string.substitute arguments, useful for specifying queryExpr: '*-bash*' inside a template without having to modify the caller or widget
---
string.js | 6 +++++-
tests/unit/string.js | 7 +++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/string.js b/string.js
index e0f5966..2e988dc 100644
--- a/string.js
+++ b/string.js
@@ -87,6 +87,7 @@ string.substitute = function( /*String*/ template,
// template:
// a string with expressions in the form `${key}` to be replaced or
// `${key:format}` which specifies a format function. keys are case-sensitive.
+ // The special sequence `${}` can be used escape `$`.
// map:
// hash to search for substitutions
// transform:
@@ -138,8 +139,11 @@ string.substitute = function( /*String*/ template,
transform = transform ?
lang.hitch(thisObject, transform) : function(v){ return v; };
- return template.replace(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g,
+ return template.replace(/\$\{([^\s\:\}]*)(?:\:([^\s\:\}]+))?\}/g,
function(match, key, format){
+ if (key == ''){
+ return '$';
+ }
var value = lang.getObject(key, false, map);
if(format){
value = lang.getObject(format, false, thisObject).call(thisObject, value, key);
diff --git a/tests/unit/string.js b/tests/unit/string.js
index 8aca6a1..7bc040e 100644
--- a/tests/unit/string.js
+++ b/tests/unit/string.js
@@ -33,6 +33,13 @@ define([
'File "foo.html" is not found in directory "/temp".'
);
+ assert.strictEqual(
+ string.substitute(
+ 'Escaped ${}'
+ ),
+ 'Escaped $'
+ );
+
assert.throws(function () {
string.substitute('${x}', { y: 1 });
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list